“JavaScript LocalStorage” Código de respuesta

Tienda JavaScript en LocalStoray

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
Grepper

Guardar en el almacenamiento local

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

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

localStorage.removeItem('myCat');

// Clear all items
localStorage.clear();
Tame Toucan

Cómo obtener datos de LocalStorage en 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
The Amateur

Javascript de almacenamiento local

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

JavaScript LocalStorage

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

document.body.addEventListener("click", function(){
  alert(localStorage.getItem("user_name"))
});
Breakable Baboon

JavaScript LocalStorage

var KeyName = window.localStorage.key(index);
Upset Unicorn

Respuestas similares a “JavaScript LocalStorage”

Preguntas similares a “JavaScript LocalStorage”

Más respuestas relacionadas con “JavaScript LocalStorage” en JavaScript

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código