如何在localStorage中存储数组?

时间:2022-01-18 15:40:41

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

我必须在window.localStorage中存储一个数组。如何使用控制台窗口将数组存储在window.localStorage中?

EX:
cards: Array[0]
length: 0

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

我必须存储这个。现在这里的关键是卡片和长度嵌套。

1 个解决方案

#1


4  

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

localStorage只支持字符串,因此您必须将其解析为JSON

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

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

JSFiddle

的jsfiddle

#1


4  

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

localStorage只支持字符串,因此您必须将其解析为JSON

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

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

JSFiddle

的jsfiddle