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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You could try iterating through all of the items in the localStorage object:
for (var i = 0; i < localStorage.length; i++){
// do something with localStorage.getItem(localStorage.key(i));
}
回答2:
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:
you can also check localStorage status and data right in the Google chrome Developer tools
回答4:
for(var i in localStorage) {
console.log(i + ' = ' + localStorage[i]);
}
回答5:
Taking hints from this page, I'm now using this:
new Array(localStorage.length)
.fill()
.map(i => localStorage.key(i));
Thanks all!
回答6:
Console log the localStorage. It's very simple.
console.log(localStorage);