[英]Why is my object's value delete when I try to turn it to array?
The code below is returning an empty array.下面的代码返回一个空数组。 Why?
为什么?
var jsonparse = Array.from(JSON.parse(localStorage.getItem("user")))
console.log(jsonparse)
//it's a object which i turn to string by json.stringify
//but then i want to use it in two form one obj sec array i don't know how to turn it correctly a array
//is retuning me an empty array why?
//expected output:-
//[{key:"value"}]
//real output
//[]
you can see what is in my localstorage by going to the link of an img (i have took an screen shot of my localstorage):-您可以通过转到 img 的链接来查看我的本地存储中的内容(我已经截取了我的本地存储的屏幕截图):-
https://i.stack.imgur.com/OWZ9u.png
https://i.stack.imgur.com/OWZ9u.png
first confirm that localStorage.getItem("user")
is an object.首先确认
localStorage.getItem("user")
是 object。 then change your statement syntax as I have written below.然后按照我在下面写的那样更改您的语句语法。
var jsonparse = Array.from([JSON.parse(JSON.stringify(localStorage.getItem("user")))])
this will make the array you want:这将使您想要的数组:
var array = [];
array.push(JSON.parse(localStorage.getItem("user")))
console.log(array)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.