views:

36

answers:

1

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

+1  A: 

Try

for(var i=0; i<600; i++) {
    localStorage.setItem(i, localStorage.getItem(i) + "new data");
}
Andrew67
I belive that this could work. Ill check it out and get back to you
Mircea
Thanx this works!
Mircea