If you want to store Javascript objects in local storage, you can use HTML5 local storage.
Here is the code :-
var dashboard-data = { 'one': 1, 'two': 2, 'three': 3 };
// Put the object into storage
localStorage.setItem('dashboard-data', JSON.stringify(dashboard-data));
// Retrieve the object from storage
var proData = localStorage.getItem('proData');
console.log('proData: ', JSON.parse(proData));
setItem will set all the items and getItem will retrieve all the items. Before storing it stringify your object and later parse it when you retrieve it.
If you are using JSON.stringify() for storing objects, then this function can not serialise private members. This issue can be solved by using the .toString().
0 Comment(s)