我正在尝试使用 map 向我的对象添加一个新的键和值对。该值只是一个空数组,因此我可以稍后将对象推入其中。
这是我的代码:
let columns = [
{
_id: "5e8af4591c9d440000a1a4ed",
column_name: "Opportunities",
column_value: 0,
column_percentage: 0.25
},
{
_id: "5e8af4a81c9d440000a1a4ee",
column_name: "Prospects",
column_value: 0,
column_percentage: 0.5
}
];
let output = columns.map(() => ({posts: []}));
console.log(output)
这是我希望我的对象在映射后的样子:
let columns = [
{
_id: "5e8af4591c9d440000a1a4ed",
column_name: "Opportunities",
column_value: 0,
column_percentage: 0.25,
posts: []
},
{
_id: "5e8af4a81c9d440000a1a4ee",
column_name: "Prospects",
column_value: 0,
column_percentage: 0.5,
posts: []
}
];
但目前的输出是:
[
{
posts: []
},
{
posts: []
}
]
一只斗牛犬
皈依舞
不负相思意
蝴蝶不菲
随时随地看视频慕课网APP
相关分类