retrieve localstorage data javascript code example
Example 1: how to get all items in localstorage
function allStorage() {
var values = [],
keys = Object.keys(localStorage),
i = keys.length;
while ( i-- ) {
values.push( localStorage.getItem(keys[i]) );
}
return values;
}
Example 2: how to get data from localstorage in javascript
var data = JSON.parse(localStorage.getItem("key name"));
Example 3: how to get variable in local storage in javascript
localStorage.getItem('id');
Example 4: get localstorage value
localStorage.getItem('bgcolor');