I want to acess all the localStorage variables saved on a specific page. How do I do that? I want to show it like I would show an array with the join() function
我想访问保存在特定页面上的所有localStorage变量。我怎么做?我想显示它就像我将使用join()函数显示一个数组
5 个解决方案
#1
79
You could try iterating through all of the items in the localStorage object:
您可以尝试遍历localStorage对象中的所有项:
for (var i = 0; i < localStorage.length; i++){
// do something with localStorage.getItem(localStorage.key(i));
}
#2
21
I use this block of code frequently:
我经常使用这段代码:
var i;
console.log("local storage");
for (i = 0; i < localStorage.length; i++) {
console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]");
}
console.log("session storage");
for (i = 0; i < sessionStorage.length; i++) {
console.log(sessionStorage.key(i) + "=[" + sessionStorage.getItem(sessionStorage.key(i)) + "]");
}
#3
9
you can also check localStorage status and data right in the Google chrome Developer tools
您还可以在Google Chrome开发人员工具中查看localStorage状态和数据
#4
4
for(var i in localStorage) {
console.log(i + ' = ' + localStorage[i]);
}
#5
0
Taking hints from this page, I'm now using this:
从这个页面获取提示,我现在正在使用这个:
new Array(localStorage.length)
.fill()
.map(i => localStorage.key(i));
Thanks all!
谢谢大家!
#1
79
You could try iterating through all of the items in the localStorage object:
您可以尝试遍历localStorage对象中的所有项:
for (var i = 0; i < localStorage.length; i++){
// do something with localStorage.getItem(localStorage.key(i));
}
#2
21
I use this block of code frequently:
我经常使用这段代码:
var i;
console.log("local storage");
for (i = 0; i < localStorage.length; i++) {
console.log(localStorage.key(i) + "=[" + localStorage.getItem(localStorage.key(i)) + "]");
}
console.log("session storage");
for (i = 0; i < sessionStorage.length; i++) {
console.log(sessionStorage.key(i) + "=[" + sessionStorage.getItem(sessionStorage.key(i)) + "]");
}
#3
9
you can also check localStorage status and data right in the Google chrome Developer tools
您还可以在Google Chrome开发人员工具中查看localStorage状态和数据
#4
4
for(var i in localStorage) {
console.log(i + ' = ' + localStorage[i]);
}
#5
0
Taking hints from this page, I'm now using this:
从这个页面获取提示,我现在正在使用这个:
new Array(localStorage.length)
.fill()
.map(i => localStorage.key(i));
Thanks all!
谢谢大家!