Last active
April 30, 2022 12:06
-
-
Save brunnerh/14b8585978399d47a69a788379a93805 to your computer and use it in GitHub Desktop.
Function for enumerating storage contents.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Turns a storage into an array of key/value tuples. | |
* (Same format as the result of {@link Object.entries}.) | |
* @param {Storage} storage A storage instance (e.g. {@link Window.localStorage}). | |
* @returns {[string, string][]} Key/value tuple array of entries. | |
*/ | |
function entriesFromStorage(storage) { | |
return new Array(storage.length).fill(0) | |
.map((e, i) => storage.key(i)) | |
.map(key => [key, storage.getItem(key)]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment