简体   繁体   中英

finding list of elements in the local storage

I'm storing json strings representing objects in the local storage. I write something like this:

window.localStorage.setItem('ItemID' + TheItemID, TheItemInJson);

Now I need to know which items are in the storage. What's a good way to do this?

Thanks.

You would like to use this code:

for(var i=0, len=localStorage.length; i<len; i++) {
    var key = localStorage.key(i);
    var value = localStorage[key];
    console.log(key + " => " + value);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM