let arr = [ {commodity_id:1,quantity:10,amount:20}, {commodity_id:1,quantity:5,amount:10}, {commodity_id:2,quantity:10,amount:50}] mergeMap(arr) { // js数组对象相同值相加,不同添加 var newArr = []; arr.forEach(item => { var dataItem = item; if (newArr.length > 0) { var filterValue = newArr.filter(v => { return v.commodity_id == dataItem.commodity_id }) if (filterValue.length > 0) { newArr.forEach(n => { if (n.commodity_id == filterValue[0].commodity_id) { n.quantity = filterValue[0].quantity + dataItem.quantity; n.amount = filterValue[0].amount + dataItem.amount; } }) } else { newArr.push(dataItem) } } else { newArr.push(dataItem) } }); return newArr }, console.log(mergeMap(arr))