我在这里有一个真正的大脑冻结时刻。我有一个对象数组,我需要将它们转换为仅属性数组。克服这个问题的最佳方法是什么?
[
{
user_id: 302
},
{
send_user_email: true
},
{
send_admin_email: true
}
]
对此;
[
user_id: 302,
send_user_email: true,
send_admin_email: true
]
答案 0 :(得分:3)
您可以使用Object.assign
:
const array = [
{
user_id: 302
},
{
send_user_email: true
},
{
send_admin_email: true
}
];
const result = Object.assign({}, ...array);
console.log(result);