Skip to content

Instantly share code, notes, and snippets.

Embed
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);
@TutorFx
Copy link

TutorFx commented Feb 10, 2021

Thank you!

@Andrewsabatyuk
Copy link

Andrewsabatyuk commented Jun 27, 2021

and how to rewrite?

@S-codes14
Copy link

S-codes14 commented Oct 24, 2021

nice solution

@shahhhashmatali2002
Copy link

shahhhashmatali2002 commented Mar 26, 2022

Thanks a lot bro for this solution

@HeshamRefai
Copy link

HeshamRefai commented Apr 10, 2022

nice solution

@BenjaminCOlds
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