how to save to local storage code example
Example 1: javascript store object in local storage
var person = { "name": "billy", "age": 23};
localStorage.setItem('person', JSON.stringify(person));
var retrievedPerson = JSON.parse(localStorage.getItem('person'));
Example 2: save to local storage
localStorage.setItem('myCat', 'Tom');
var cat = localStorage.getItem('myCat');
localStorage.removeItem('myCat');
localStorage.clear();
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: local storage javascript
localStorage.setItem('user_name', 'Rohit');
var retrievedUsername = localStorage.getItem('user_name');
Example 5: save to local storage
localStorage.setItem('myCat', 'Tom');
Example 6: save to local storage
var cat = localStorage.getItem('myCat');