Created
December 23, 2012 18:08
-
-
Save jbail/4364947 to your computer and use it in GitHub Desktop.
Local storage with JSON parse and stringify
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
var animal = { | |
name: 'Karl', | |
type: 'cat', | |
color: 'black', | |
age: 7 | |
}; | |
//convert JSON animal into a string | |
var dehydratedAnimal = JSON.stringify(animal); | |
//save it with local storage | |
window.localStorage.setItem('animal', dehydratedAnimal); | |
//get 'animal' and rehydrate it (convert it back JSON) | |
var rehydratedAnimal = JSON.parse(window.localStorage.getItem('animal')); |
You can access it using ".", for example:
alert(rehydratedAnimal.name);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how can i access to the rehydratedAnimal properties?, i tried to use it how an object, but isn't working :(