chrisstump
2/5/18 at 10:17 am
JavaScript
local storage
Store an Object in Local Storage
Creating a variable as an object first, we can then assign that variable to a local storage item that we can later retrieve and use accordingly.
// see here for more info: // https://stackoverflow.com/questions/2010892/storing-objects-in-html5-localstorage var testObject = { 'one': 1, 'two': 2, 'three': 3 }; // Put the object into storage localStorage.setItem('testObject', JSON.stringify(testObject)); // Retrieve the object from storage var retrievedObject = localStorage.getItem('testObject'); console.log('retrievedObject: ', JSON.parse(retrievedObject));
Copy Snippet to Clipboard
Don't Have an Account?
Stop digging through old code examples. Get organized. Get Code Snipper.
Learn More
Start Free 14 Day Trial