1

我有以下 localStorage 键:

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

如何在循环中附加到这些 Keys 新数据?

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

这将覆盖我的原始密钥,而不是将“新数据”附加到“某些数据”。谢谢

4

1 回答 1

2

尝试

for(var i=0; i<600; i++) {
    localStorage.setItem(i, localStorage.getItem(i) + "new data");
}
于 2010-09-18T15:17:21.403 回答