I am not able to restore a created array in html and reuse it again. I have used Json but do not work with me. in the below code. I'm trying to reload items which is an array created in another page. when i try to load it, it did not work. how can i fix this? does json need header file? Thank you.
$( document ).ready(function() {
var count=sessionStorage.getItem('items');
)};
The sessionStorage
property allows you to access a session Storage object for the current origin.It is two way process first of all stringify
object before storing to session and second parse
to getting back .
var user = {'name':'John'};
sessionStorage['user'] = JSON.stringify(user);
console.log(sessionStorage['user']);
var obj = JSON.parse(sessionStorage['user']);
console.log(Object.keys(obj).length);
Here is fiddle.Opening a page in a new tab or window will cause a new session to be initiated. More About session storage.