javascript getitem 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 setItem and getItem in javascript in localStorage
function set(){
var sendJSON = JSON.stringify(allMovie);
localStorage.setItem('allMovie',sendJSON)
}
function get(){
var getJSON = localStorage.getItem('allMovie');
if (getJSON){
allMovie = JSON.parse(getJSON)
}
}
Example 3: get localstorage
var pull=JSON.parse(localStorage.getItem('data'))
for(var i=0; i<pull.length; i++){
new ConstrcterName(pull[i].AnyName, pull[i].AnyName, pull[i].AnyName)
}
for(var o=0; o<arrayName.length; o++){
ArrayName[o].getRandom();
ArrayName[o].showRow();
Example 4: localstorage.getitem()
localStorage.setItem('myCat', 'Tom');
const cat = localStorage.getItem('myCat');
localStorage.removeItem('myCat');
localStorage.clear();