LocalStorage lets you save bits of data that will be there the next time that same user visits the same page on that same browser.
LocalStorage acts sort of like an object hash -- but you should use its get
and set
methods, not []
or .
notation.
set an item
localStorage.setItem('myCat', 'Tom');
get an item
var cat = localStorage.getItem('myCat');
remove an item
localStorage.removeItem('myCat');
clear all items
localStorage.clear();
but you can use this one weird trick to save a nested object:
set an item
localStorage.setItem('myCat', JSON.stringify(cat));
get an item
var cat = JSON.parse(localStorage.getItem('myCat'));
/