Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store array in localStorage?

I have to store an array in window.localStorage. How would I store the array in window.localStorage using console window?

EX:
cards: Array[0]
length: 0

I have to store this. Now here key is cards and length is nested.

like image 373
Kunal Gawhade Avatar asked May 20 '26 00:05

Kunal Gawhade


1 Answers

localStorage only support string so you'll have to parse it to JSON

var arr = ["hello", "how", "are", "you", "doing"];

localStorage.setItem("test", JSON.stringify(arr));

JSFiddle

like image 60
Nick Avatar answered May 22 '26 15:05

Nick