Skip to content

Instantly share code, notes, and snippets.

@soggybag
Created December 13, 2016 03:39
Show Gist options
  • Save soggybag/f846029e2b555300dfbe7359f4340865 to your computer and use it in GitHub Desktop.
Save soggybag/f846029e2b555300dfbe7359f4340865 to your computer and use it in GitHub Desktop.
// Local storage
// Create an object
var obj = {name:"Joe", age:33, shoesize:9.5, favoriteFoods:["Apples", "Bananas"]};
// Convert object to JSON string
var objJSON = JSON.stringify(obj);
// save JSON string to local storage with the key obj.
localStorage.setItem("obj", objJSON);
// Retrieve data from localstorage
var storedObjJSON = localStorage.getItem("obj");
// Convert JSON string to JS Obj
var newObj = JSON.parse(storedObjJSON);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment