“Localstorage API” Ответ

Сохранить на местном хранилище

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

LocalStorage

// 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

Ответы похожие на “Localstorage API”

Вопросы похожие на “Localstorage API”

Больше похожих ответов на “Localstorage API” по JavaScript

Смотреть популярные ответы по языку