javascript - save array values on reload and retrieve it back -


i pushing random values array every minute.

on reloading want retrieve pushed content , keep pushing random data every minute?

i using local storage.

mycode--:

localstorage.setitem("test",myarray.push(json.stringify(data))); var test2 = localstorage.getitem("test"); test = json.parse(test2); //var test re-loaded! console.log(test); 

this not working.

push data array, store in localstorage json:

// set myarray.push(data); localstorage.setitem("test", json.stringify(myarray)); 

parse json when data out (put @ top of script, or in onload method):

// if (localstorage.getitem("test")) {     myarray = json.parse(localstorage.getitem("test")); } else {     // no data, start empty array     myarray = []; } console.log(myarray); 

Comments