Storing array in localStorage with JSON in javascript

后端 未结 2 1975
无人及你
无人及你 2021-01-22 16:55

I have refereed this question and worked for me: so q1

Now Issue is that I have used JSON.stringify & JSON.parse to store array in localStorage. But when I run the

相关标签:
2条回答
  • 2021-01-22 17:01
    var myString = JSON.parse(localStorage['bankpro']);
    

    JSON.parse returns a javascript object, not a string, which would not have a split method.

    0 讨论(0)
  • 2021-01-22 17:01

    If you store an Array in LocalStorage using JSON.stringify, then you get it back using JSON.parse, return value is Array, not string. So when you are using function mySplitResult for myString (which is actually Array, thanks to JSON.parse), then it leads to an Error. So remove function mySplitResult and it should work fine.

    0 讨论(0)
提交回复
热议问题