“LocalStorage API” Kode Jawaban

Simpan ke Penyimpanan Lokal

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

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

localStorage.removeItem('myCat');

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

JS LocalStorage

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

penyimpanan lokal

// localStorage for objects, arrays or any data type
var obj = {
	firstName: "Bob",
    lastName: "Jeff",
    age: 13
}
localStorage.setItem("itemname", JSON.stringify(obj)); // Save the obj as string
var item = JSON.parse(localStorage.getItem("itemname")); 
// ^^ Parse string then set `item` as the obj
sunst0rm

JavaScript LocalStorage

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

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

LocalStorage JS

// Set
localStorage.setItem('monChat', 'Tom');

// Get
localStorage.getItem('myCat');

// Remove
localStorage.removeItem('myCat');
Lively Leopard

LocalStorage API

localStorage //to see localStorage data
localStorage.clear() // to clear all the localStorage data
localStorage.setItem("something") // to set a localStorage Item
localStorage.getItem("something") //to read the localStorage data
localStorage.removeItem("something") // to remove the localStorage data
Disturbed Dingo

Jawaban yang mirip dengan “LocalStorage API”

Pertanyaan yang mirip dengan “LocalStorage API”

Lebih banyak jawaban terkait untuk “LocalStorage API” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya