简体   繁体   English

在本地存储中查找元素列表

[英]finding list of elements in the local storage

I'm storing json strings representing objects in the local storage. 我将代表对象的json字符串存储在本地存储中。 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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