1var testObject = { 'one': 1, 'two': 2, 'three': 3 };
2
3// Put the object into storage
4localStorage.setItem('testObject', JSON.stringify(testObject));
5
6// Retrieve the object from storage
7var retrievedObject = localStorage.getItem('testObject');
8
9console.log('retrievedObject: ', JSON.parse(retrievedObject));
1//Set item
2localStorage.setItem('myCat', 'Tom');
3//Get item
4var cat = localStorage.getItem("myCat");
5//Remove item
6localStorage.removeItem("lastname");
7//Remove all items
8localStorage.clear();
1localStorage.setItem('myCat', 'Tom');
2
3var cat = localStorage.getItem('myCat');
4
5localStorage.removeItem('myCat');
6
7// Clear all items
8localStorage.clear();
9
1// Store
2localStorage.lastname = "Smith";
3// Retrieve
4document.getElementById("result").innerHTML = localStorage.lastname;
5// Remove
6localStorage.removeItem("lastname");