开发者

HTML5 localStorage apped new data to already existing keys

开发者 https://www.devze.com 2023-01-17 03:54 出处:网络
I have the following localStorage keys: localStorage.setItem(1, \"some data\"); localStorage.setItem(2, \"some data\");

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

精彩评论

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