对象数组根据对象的某个或多个属性进行去重和某个属性合计

this.details2=arr.reduce((total, cur, index) => {

let hasValue = total.findIndex(current => { return current.size === cur.size && current.po === cur.po  && current.color === cur.color})

hasValue === -1 && total.push(cur)

hasValue !== -1 && (total[hasValue].singleQuantity = total[hasValue].singleQuantity + cur.singleQuantity)

return total

}, [])

你可能感兴趣的:(对象数组根据对象的某个或多个属性进行去重和某个属性合计)