LocalStorage only support strings.
Use JSON.parse
and JSON.stringify()
:
var data = JSON.parse(localStorage.getItem("data"));
var data = ['foo', 'bar'];
localStorage.setItem("data", JSON.stringify(data));
Categorieën
JavaScript