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");
}
精彩评论