0 points

How to store an array in localstorage js


dashboard

Wed Oct 21 2020 15:28:14 GMT+0000 (UTC)

Posted by @vrzi #javascript

// Store an array in local storage

// The array to store
var array = [1, 2, 3];
// Store after JSON stringifying (is this a verb?) it
localStorage.setItem('myArray', JSON.stringify(array));

// Get an array from local storage

// Retrieve the array from local storage
var array = localStorage.getItem('myArray');
// Parse it to something usable in js
array = JSON.parse(array);
content_copy Copy

https://gist.github.com/nrojas13/68b79e21d0c81aa22ad762c9a4db38d0