I have localstorage working to where I can save inputs and push them to a list. Now I would like to save the list in localstorage because when I reload the list resets because of var fav = new Array();
is defined at the start in this jsFiddle. How can I work around this?
Thanks, Ben
Save Array In localStorageYou can save the array by using the setItem method. const myBlogs = ["https://catalins.tech", "https://exampleblog.com"]; localStorage. setItem('links', JSON. stringify(myBlogs));
The localStorage API in browsers only supports adding information in a key:pair format and the key and the pair should be of type string thus native objects or arrays cannot be stored in the localStorage .
The clear() method of the Storage interface clears all keys stored in a given Storage object.
It's realy easy, you just need to use JSON data to save it :
// Save
var datas = ["1", "2", "3"];
localStorage["datas"] = JSON.stringify(datas);
// Retrieve
var stored_datas = JSON.parse(localStorage["datas"]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With