Languages
[Edit]
EN

JavaScript - store array in localStorage

0 points
Created by:
Zoya-Gaines
653

In this article, we would like to show you how to store an array in localStorage using JavaScript.

1. Store array in localStorage

Edit

Since localStorage only supports strings, arrays must be converted to a string format.

In this example, we use JSON.stringify() method to convert array to string and then setItem() method to save the items array in the localStorage.

2. Get array from localStorage

Edit

When we want to get the array from the localStorage, we need to convert it back to the array type (since we can only get a string from the localStorage).

In this example, we use getItem() method to get items array from the localStorage and JSON.parse() to convert the string back to the array type.

 

See also

Edit
  1. JavaScript - how to use localStorage

References

Edit
  1. Window.localStorage - Web APIs | MDN

Alternative titles

  1. JavaScript - store array in local storage
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join