“JavaScript LocalStorage” Code-Antworten

JavaScript Store in LocalStorage

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

Speichern im lokalen Speicher

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

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

localStorage.removeItem('myCat');

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

So erhalten Sie Daten von 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
The Amateur

Lokaler Speicher 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';
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

Ähnliche Antworten wie “JavaScript LocalStorage”

Fragen ähnlich wie “JavaScript LocalStorage”

Weitere verwandte Antworten zu “JavaScript LocalStorage” auf JavaScript

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen