localstorage api code example
Example 1: save to local storage
localStorage.setItem('myCat', 'Tom');
var cat = localStorage.getItem('myCat');
localStorage.removeItem('myCat');
localStorage.clear();
Example 2: localstorage js
localStorage.setItem('monChat', 'Tom');
localStorage.getItem('myCat');
localStorage.removeItem('myCat');
Example 3: local storage
function setItem(name, value) {
localStorage.setItem(name, value);
}
function getItem(name) {
localStorage.getItem(name);
}
function deletItem(name) {
localStorage.removeItem(name);
}
function clearStorage() {
localStorage.clear();
}
Example 4: localStorage
var obj = {
firstName: "Bob",
lastName: "Jeff",
age: 13
}
localStorage.setItem("itemname", JSON.stringify(obj));
var item = JSON.parse(localStorage.getItem("itemname"));
Example 5: localstorage
window.localStorage.setItem('myCat', 'Tom');
const cat = window.localStorage.getItem('myCat');
Example 6: localstorage
var cat = localStorage.getItem('myCat');