Answers for "sessionstorage vs localstorage"

7

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
Posted by: Guest on May-20-2020
-1

session storage vs local storage

// Save data to sessionStorage
sessionStorage.setItem('key', 'value');

// Get saved data from sessionStorage
let data = sessionStorage.getItem('key');

// Remove saved data from sessionStorage
sessionStorage.removeItem('key');

// Remove all saved data from sessionStorage
sessionStorage.clear();
Posted by: Guest on June-09-2021
0

localstorage

localStorage.removeItem('myCat');
Posted by: Guest on August-09-2020

Code answers related to "sessionstorage vs localstorage"

Code answers related to "Javascript"

Browse Popular Code Answers by Language