Get local storage javascript code example
Example 1: javascript set local storage value
var testObject = { 'one': 1, 'two': 2, 'three': 3 };
localStorage.setItem('testObject', JSON.stringify(testObject));
var retrievedObject = localStorage.getItem('testObject');
console.log('retrievedObject: ', JSON.parse(retrievedObject));
Example 2: get localstorage
function get(){
var getJson = localStorage.getItem('key')
if(getJson){
arrayName = JSON.parse(getJson)
}
}
Example 3: local storage javascript
function createItem() {
localStorage.setItem('nameOfItem', 'value');
}
createItem()
function getValue() {
return localStorage.getItem('nameOfItem');
}
console.log(getValue());
Example 4: javascript get local storage
var Item = localStorage.getItem('youritem');
Example 5: save to local storage
localStorage.setItem('myCat', 'Tom');
Example 6: 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)