How to store array in localStorage?

后端 未结 1 1313
借酒劲吻你
借酒劲吻你 2021-01-21 00:11

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

EX:
cards: Ar         


        
相关标签:
1条回答
  • 2021-01-21 00:42

    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 讨论(0)
提交回复
热议问题