如何在localStorage中存储阵列? [英] How to store array in localStorage?

查看:50
本文介绍了如何在localStorage中存储阵列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将一个数组存储在window.localStorage中.如何使用控制台窗口将数组存储在window.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.

推荐答案

localStorage仅支持string,因此您必须将其解析为JSON

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

这篇关于如何在localStorage中存储阵列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆