Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
const fruits = {
apples: 3,
bananas: 4,
pears: 1,
blackberries: 8
// always check if Storage is available
if (typeof(Storage)) {
// saving the object (or JSON) to localStorage
localStorage.setItem("fruits", JSON.stringify(fruits));
// retrieving the stringified object from localStorage
// clearing the "fruits" key and value, now if you try to access it - it's null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment