最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to store array in localStorage? - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question edited Feb 18, 2016 at 10:04 CG_FD 6071 gold badge5 silver badges16 bronze badges asked Feb 18, 2016 at 9:05 Kunal GawhadeKunal Gawhade 311 silver badge2 bronze badges 1
  • 1 JSON.stringify() and JSON.parse() upon reading? – entio Commented Feb 18, 2016 at 9:07
Add a ment  | 

1 Answer 1

Reset to default 5

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

发布评论

评论列表(0)

  1. 暂无评论