Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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);
Copy link

TutorFx commented Feb 10, 2021

Thank you!

Copy link

Andrewsabatyuk commented Jun 27, 2021

and how to rewrite?

Copy link

S-codes14 commented Oct 24, 2021

nice solution

Copy link

shahhhashmatali2002 commented Mar 26, 2022

Thanks a lot bro for this solution

Copy link

HeshamRefai commented Apr 10, 2022

nice solution

Copy link

BenjaminCOlds commented May 26, 2022

Thank you so much!

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