Store and retrieve data from local storage
let myObj, myJSON, text, obj;

// Storing data:
myObj = { name: "John", age: 31, city: "New York" };
myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);

// Retrieving data:
text = localStorage.getItem("testJSON");
obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name + ' is ' + obj.age;
by Valeri Tandilashvili
4 years ago
JSON
JavaScript
JS JSON
1
Pro tip: use ```triple backticks around text``` to write in code fences