window.localstorage in javascript code example

Example 1: javascript set localstorage

// SET
localStorage.setItem('myCat', 'Link');

// GET
let aValue = localStorage.getItem('myCat');

Example 2: local storage javascript

localStorage.setItem('user_name', 'Rohit'); //store a key/value
var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key

Example 3: localstorage javascript

localStorage.setItem(key, val);
var val = localStorage.getItem(key);
localStorage.removeItem(key);
localStorage.clear();

Example 4: my local storage

/* function for setIetm to local storage */

function set(){
    var sendJson = JSON.stringify(allwish);
    localStorage.setItem("wishKay",sendJson);
}