localStorage
only supports strings. Use JSON.stringify()
and JSON.parse()
.
var names = [];
names[0] = prompt("New member name?");
localStorage.setItem("names", JSON.stringify(names));
//...var storedNames = JSON.parse(localStorage.getItem("names"));
You can also use direct access to set/get item:
localstorage.names = JSON.stringify(names);
var storedNames = JSON.parse(localStorage.names);
Demo URl
https://stackblitz.com/edit/js-k29afs?file=index.js
Fig.1 |
No comments:
Post a Comment