product = [{id: 52, title: "cake", price: "10", category: "cakes"}]
我有一个带有产品的对象,它是对象数组,我想将上述对象数组转换为如下对象:
{id: 52, title: "cake", price: "10", category: "cakes"}
我该怎么做?
答案 0 :(得分:-2)
使用 Object.assign
分配给对象
演示
product= [{id: 52, title: "cake", price: "10", category: "cakes"}]
newproduct = Object.assign({}, ...product);
console.log(newproduct);