*如何合并下面这样的数据是我的数据
我们应该做什么*
所有使用reduce + concat和merge但仍无效的解决方案
[
{
employeeName: 'វី រឿន',
docStudyFee: 415.24,
docBusFee: 50,
docSaleFee: 10,
amount: 475.24
},
{ items:
[
[Object],
[Object],
[Object],
]
},
]
这样的结果
[{
employeeName: 'វី រឿន',
docStudyFee: 415.24,
docBusFee: 50,
docSaleFee: 10,
amount: 475.24 ,
items:
[
[Object],
[Object],
[Object],
]
}]
答案 0 :(得分:1)
Object.assign({}, ...yourArray)
或
yourArray.reduce((obj, el) => Object.assign(obj, el), {})
如果你真的需要一个包含一个对象而不是直接对象的数组,请将上面的oneliners包装到[]
答案 1 :(得分:-1)
Yourarray [O] .items = Yourarray [1] .items; Yourarray.pop();