saving to local storeage javascipt code example
Example 1: set localstorage
function set(){
var sendJson = JSON.stringify(arrayName);
localStorage.setItem('key',sendJson)
}
Example 2: localstorage
// using in HTML5 (frontend)
// set
localStorage.setItem('users', 'vilh');
users = [
{
id: 1,
name: 'vilh',
},
{
id: 2,
name: 'zidane'
},
]
// set string
localStorage.setItem('users', users); // stored objects
localStorage.setItem('users', JSON.stringify(users)); // stored string
// get
var retrievedUsername = localStorage.getItem('users');