How to store an array in localstorage js

PHOTO EMBED

Wed Oct 21 2020 15:28:14 GMT+0000 (Coordinated Universal Time)

Saved 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_copyCOPY

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