admin管理员组

文章数量:1427307

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

本文标签: javascriptHow to store array in localStorageStack Overflow