javascript local storage example
Example 1: local storage javascript
function createItem() {
localStorage.setItem('nameOfItem', 'value');
}
createItem()
function getValue() {
return localStorage.getItem('nameOfItem');
}
console.log(getValue());
Example 2: local storage javascript
localStorage.setItem('user_name', 'Rohit');
var retrievedUsername = localStorage.getItem('user_name');
Example 3: localStorage
var obj = {
firstName: "Bob",
lastName: "Jeff",
age: 13
}
localStorage.setItem("itemname", JSON.stringify(obj));
var item = JSON.parse(localStorage.getItem("itemname"));
Example 4: local storage javascript
let storage = window.localStorage;
storage.setItem("highscore", 76);
let highscore = storage.getItem("highscore");
storage.removeItem("highscore");
storage.clear();
Example 5: javascript localstorage
var KeyName = window.localStorage.key(index);