Kunal Gawhade
Kunal Gawhade

Reputation: 31

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.

Upvotes: 3

Views: 5041

Answers (1)

Nick
Nick

Reputation: 3281

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

Upvotes: 5

Related Questions