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
js
localStorage.setItem('myCat', 'Tom');
get an item
js
let cat = localStorage.getItem('myCat');
remove an item
js
localStorage.removeItem('myCat');
clear all items
js
localStorage.clear();
but you can use this one weird trick to save a nested object:
set an item
js
localStorage.setItem('myCat', JSON.stringify(cat));
get an item
js
var cat = JSON.parse(localStorage.getItem('myCat'));
/