【发布时间】:2021-08-07 09:01:15
【问题描述】:
当我想将数组转换为 dict 时,它会将 const 的名称放入其中。
想要转换这个:
const hallo = {'name': 'Peter', 'lastname': 'Richard'}
收件人:
const arrayhallo = [{'name': 'Peter', 'lastname': 'Richard'}]
我试着做这样的事情:
const arrayhallo = [{hallo}]
但它会返回:
[hallo: {'name': 'Peter', 'lastname': 'Richard'}]
我只希望将字典放入数组中,但使用 .push 或这种方式我会不断获取字典的第一个名称作为索引。
【问题讨论】:
-
[{ ...hallo }]或[ hallo ]
标签: javascript arrays reactjs dictionary