如何在本地存储中存储数组?如果我不需要localStorage,我的代码将如下所示:var names=new Array(); names[0]=prompt("New member name?");这个很管用。但是,我需要将这个变量存储在localStorage中,事实证明它非常顽固。我试过:var localStorage[names] = new Array();localStorage.names[0] = prompt("New member name?");我哪里出错了?
3 回答
翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
localStorage
JSON.stringify()
JSON.parse()
.
var names = [];names[0] = prompt("New member name?");localStorage.setItem("names", JSON.stringify(names)); //...var storedNames = JSON.parse(localStorage.getItem("names"));
隔江千里
TA贡献1906条经验 获得超10个赞
JSON.stringify()
JSON.parse()
three|||bars
).
添加回答
举报
0/150
提交
取消