我如何显示所有localStorage保存的变量?
我想要访问保存在特定页面上的所有localStorage变量。 我怎么做? 我想展示它,就像我将使用join()函数显示数组一样
您可以尝试迭代localStorage对象中的所有项目:
for (var i = 0; i < localStorage.length; i++){
// do something with localStorage.getItem(localStorage.key(i));
}
我经常使用这段代码:
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)) + "]");
}
您还可以在Google Chrome开发人员工具中检查localStorage状态和数据
链接地址: http://www.djcxy.com/p/69997.html上一篇: How can I show all the localStorage saved variables?
下一篇: In JavaScript, create 7 variables with the same value but different names