Instantly share code, notes, and snippets.

Embed
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
JSON.parse(localStorage.getItem("fruits"))
// clearing the "fruits" key and value, now if you try to access it - it's null
localStorage.removeItem('fruits');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment