Skip to content

Instantly share code, notes, and snippets.

@nrojas13
Created November 3, 2016 23:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nrojas13/68b79e21d0c81aa22ad762c9a4db38d0 to your computer and use it in GitHub Desktop.
Save nrojas13/68b79e21d0c81aa22ad762c9a4db38d0 to your computer and use it in GitHub Desktop.
How to store an array in localstorage js
// 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);
@HeshamRefai
Copy link

nice solution

@BenjaminCOlds
Copy link

Thank you so much!

@hashmod
Copy link

hashmod commented Dec 29, 2022

Best solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment