“LocalStorage di JS” Kode Jawaban

JavaScript mengatur nilai penyimpanan lokal

var testObject = { 'one': 1, 'two': 2, 'three': 3 };

// Put the object into storage
localStorage.setItem('testObject', JSON.stringify(testObject));

// Retrieve the object from storage
var retrievedObject = localStorage.getItem('testObject');

console.log('retrievedObject: ', JSON.parse(retrievedObject));
Mobile Star

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

JavaScript mendapatkan penyimpanan lokal

  var Item = localStorage.getItem('youritem');
Xenophobic Xenomorph

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

JavaScript penyimpanan lokal

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

LocalStorage di JS

// Check browser support
if (typeof(Storage) !== "undefined") {
  // Store
  localStorage.setItem("lastname", "Smith");
  // Retrieve
  document.getElementById("result").innerHTML = localStorage.getItem("lastname");
} else {
  document.getElementById("result").innerHTML = "Sorry, your browser does not support Web Storage...";
}
Outrageous Osprey

Jawaban yang mirip dengan “LocalStorage di JS”

Pertanyaan yang mirip dengan “LocalStorage di JS”

Lebih banyak jawaban terkait untuk “LocalStorage di JS” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya