Answers for "local.storage javascript"

28

local storage javascript object

var person = { "name": "billy", "age": 23};

localStorage.setItem('person', JSON.stringify(person)); //stringify object and store
var retrievedPerson = JSON.parse(localStorage.getItem('person')); //retrieve the object
Posted by: Guest on July-22-2019
5

javascript localstorage

localStorage.setItem("user_name", "Bob");

document.body.addEventListener("click", function(){
  alert(localStorage.getItem("user_name"))
});
Posted by: Guest on May-14-2020
1

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');
Posted by: Guest on November-04-2020
-1

local storage

window.localStorage.setItem("grade","One");
//in this case, the `grade` is the key while `One` is the value.
Posted by: Guest on October-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language