Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Local storage with JSON parse and stringify
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'));
Copy link

RizoMan commented Jul 31, 2019

how can i access to the rehydratedAnimal properties?, i tried to use it how an object, but isn't working :(

Copy link

proncaglia commented Aug 10, 2021

You can access it using ".", for example:


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment