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));
1localStorage.setItem('user_name', 'Rohit'); //store a key/value
2var retrievedUsername = localStorage.getItem('user_name'); //retrieve the key
1//localStorage is an object, so values are stored by key name
2//data from localStorage is always stored in strings
3//usually the values at each key are stringified objects in JSON format, therefore we must parse them
4var data = JSON.parse(localStorage.getItem("key name"));//make sure the "key name" exists in the localStorage