Last active
April 4, 2019 12:37
-
-
Save abachuk/a35c5c4dd900af0e903bef541018c057 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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