为什么在尝试将其值转换为数组时删除该对象的值?

时间:2020-06-29 16:14:00

标签: javascript arrays object

下面的代码返回一个空数组。为什么?

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
//[]

您可以通过转到img的链接来查看我的本地存储中的内容(我对本地存储进行了截屏):-

https://i.stack.imgur.com/OWZ9u.png

2 个答案:

答案 0 :(得分:0)

首先确认image: andthensome/docker-node-rsync pipelines: branches: staging: - step: name: Build and deploy to staging caches: - node script: - mkdir -p ~/.ssh # fails here: - envsubst < .env.staging - cat .env.staging - npm install - npm run production - rsync -avz --delete public/compiled-assets/ root@redacted.org:/home/public/compiled-assets - ssh root@redacted.org 'bash -s' < devops/deploy_staging.sh 是一个对象。 然后按照我在下面的说明更改语句的语法。

localStorage.getItem("user")

答案 1 :(得分:-1)

这将创建您想要的数组:

var array = [];
array.push(JSON.parse(localStorage.getItem("user")))
console.log(array)