开发者

HTML5 localStorage apped new data to already existing keys

I have the following localStorage keys:

localStorage.setItem(1, "some data");
localStorage.setItem(2, "some data");
localStorage.setItem(3, "some data");
.
.
.
localStorage.setItem(600, "some data");

How can I append to those Keys new data in a loop?

var i = 0
for(h=0;h<600;h++) {
key = i++;
localStorage.setItem(key, "new data");
}

This will overwrite my开发者_开发知识库 original keys and not append the "new data" to "some data". Thank you


Try

for(var i=0; i<600; i++) {
    localStorage.setItem(i, localStorage.getItem(i) + "new data");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜