localstorage php code example

Example 1: localstorage

var cat = localStorage.getItem('myCat');

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');

Example 3: localstorage

localStorage.setItem('myCat', 'Tom');

Example 4: localstorage

localStorage.removeItem('myCat');