【发布时间】:2022-08-03 17:40:36
【问题描述】:
我正在开发一个 node.js 项目,而我正在尝试做的是在对象中推送一个值。 对象是:
{
phone: \'1234\',
fullName: \'John\',
_id: new ObjectId(\"62ea3f5e6e03a2ffec2ddb83\"),
createdAt: 2022-08-03T09:26:54.298Z
}
我试图添加到此对象的是活动/非活动状态。
{
phone: \'+1234\',
fullName: \'John\',
_id: new ObjectId(\"62ea3f5e6e03a2ffec2ddb83\"),
createdAt: 2022-08-03T09:26:54.298Z,
status: \"active\" // the new value
}
我尝试过的是:
function addingProps() {
console.log(clients) // its the object of the client
clients.push({ status: \"active\"});
}
这个函数返回给我这个:
[
{
phone: \'+1234\',
fullName: \'John\',
_id: new ObjectId(\"62ea3f5e6e03a2ffec2ddb83\"),
createdAt: 2022-08-03T09:26:54.298Z,
},
{
_id: new ObjectId(\"62ea3fa57aaa2790e17ca1ad\"),
createdAt: 2022-08-03T09:28:05.890Z
}
]
如何在对象内添加status?
-
clients[0].status = \'active\'…?!
标签: javascript node.js