如何合并数组这样的东西是我的数据我们应该做什么Javascript?

时间:2018-03-17 10:31:15

标签: javascript meteor

*如何合并下面这样的数据是我的数据
我们应该做什么*
所有使用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],
       ]     
  }]

2 个答案:

答案 0 :(得分:1)

 Object.assign({}, ...yourArray)

 yourArray.reduce((obj, el) => Object.assign(obj, el), {})

如果你真的需要一个包含一个对象而不是直接对象的数组,请将上面的oneliners包装到[]

答案 1 :(得分:-1)

Yourarray [O] .items = Yourarray [1] .items; Yourarray.pop();