“LocalStorage JavaScript” Kode Jawaban

JavaScript Store di 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

Simpan ke Penyimpanan Lokal

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

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

localStorage.removeItem('myCat');

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

JavaScript penyimpanan lokal

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

LocalStorage JavaScript

localStorage.setItem('user_name', 'Rohit'); //store a key/value
var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
Grepper

JS LocalStorage

> Add item
localStorage.setItem('foo', 'bar');
> Get item
localStorage.getItem('foo');
> Remote item
localStorage.removeItem('foo');
> Clear all
localStorage.clear();
Code Cat

LocalStorage JavaScript

localStorage.setItem(key, val);
var val = localStorage.getItem(key);
localStorage.removeItem(key);
localStorage.clear();
Successful Sandpiper

Jawaban yang mirip dengan “LocalStorage JavaScript”

Pertanyaan yang mirip dengan “LocalStorage JavaScript”

Lebih banyak jawaban terkait untuk “LocalStorage JavaScript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya