Answers for "js save to local storage"

2

js save local storage

//Set item
localStorage.setItem('myCat', 'Tom');
//Get item
var cat = localStorage.getItem("myCat");
//Remove item
localStorage.removeItem("lastname");
//Remove all items
localStorage.clear();
Posted by: Guest on May-08-2021
5

save to local storage

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

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

localStorage.removeItem('myCat');

// Clear all items
localStorage.clear();
Posted by: Guest on April-27-2020
2

how to add variable to local storage in javascript

localStorage.setItem('key', 'value')
Posted by: Guest on February-28-2020
23

local storage javascript

function createItem() {
	localStorage.setItem('nameOfItem', 'value'); 
} 
createItem() // Creates a item named 'nameOfItem' and stores a value of 'value'

function getValue() {
	return localStorage.getItem('nameOfItem');  
} // Gets the value of 'nameOfItem' and returns it
console.log(getValue()); //'value';
Posted by: Guest on April-26-2020
0

how to get data from localstorage in javascript

//localStorage is an object, so values are stored by key name
//data from localStorage is always stored in strings
//usually the values at each key are stringified objects in JSON format, therefore we must parse them
var data = JSON.parse(localStorage.getItem("key name"));//make sure the "key name" exists in the localStorage
Posted by: Guest on April-02-2020
0

how to get variable in local storage in javascript

localStorage.getItem('id');
Posted by: Guest on February-28-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language