js save local storage
//Set item
localStorage.setItem('myCat', 'Tom');
//Get item
var cat = localStorage.getItem("myCat");
//Remove item
localStorage.removeItem("lastname");
//Remove all items
localStorage.clear();
js save local storage
//Set item
localStorage.setItem('myCat', 'Tom');
//Get item
var cat = localStorage.getItem("myCat");
//Remove item
localStorage.removeItem("lastname");
//Remove all items
localStorage.clear();
javascript store object in local storage
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
local storage javascript
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';
javascript get local storage
var Item = localStorage.getItem('youritem');
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
local storage javascript
localStorage.setItem('user_name', 'Rohit'); //store a key/value
var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us