如何合并对象

时间:2018-03-17 08:28:48

标签: mongodb meteor aggregate

这我的数据似乎是数据 我想在数量结果后面的对象中的项目数组

----------
[
{
 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],
           ] 
    },
}]

1 个答案:

答案 0 :(得分:0)

因此,根据需要对两个数组进行了排序,您可以:

var arr1 = [{employeeName: 'វី រឿន', docStudyFee: 415.24, docBusFee: 50, docSaleFee: 10, amount: 475.24}, ...]
var arr2 = [{ items: 
       [ 
         [Object],
         [Object],
         [Object],
       ] 
}, ...]

var result = []

for(var i=0;i<arr1.length;i++) {
  result.push(Object.assign(arr1[i], arr2[i]))
}