sessionstorage.getitem javascript code example
Example 1: session storage
sessionStorage.setItem('key', 'value');
let data = sessionStorage.getItem('key');
sessionStorage.removeItem('key');
sessionStorage.clear();
Example 2: 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 3: 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 4: get localstorage
var pull=JSON.parse(localStorage.getItem('data'))
for(var i=0; i<pull.length; i++){
new arrayName(pull[i].AnyName, pull[i].AnyName, pull[i].AnyName)
Example 5: what is sessionStorage
sessionStorage is like localStorage
except that it is cleared when the page session ends
— that is, when the page is closed.