【发布时间】:2015-09-30 21:43:07
【问题描述】:
如果我在 JS 中有一个如下所示的数组
lineitems : [{
quantity : 1,
unitPrice : 10.00,
unitPriceLessTax: 8.33,
SKU: 'SKU123456',
productName: 'Blue T-Shirt'
},
{
quantity : 1,
unitPrice : 10.00,
unitPriceLessTax: 8.33,
SKU: 'SKU123456',
productName: 'Blue T-Shirt'
},
{
quantity : 1,
unitPrice : 48.00,
unitPriceLessTax: 40.00,
SKU: 'SKU78910',
productName: 'Red Shoes'
}]
如何将其转换为如下所示
lineitems : [{
quantity : 2,
unitPrice : 10.00,
unitPriceLessTax: 8.33,
SKU: 'SKU123456',
productName: 'Blue T-Shirt'
},
{
quantity : 1,
unitPrice : 48.00,
unitPriceLessTax: 40.00,
SKU: 'SKU78910',
productName: 'Red Shoes'
}]
基本上希望根据 SKU 合并重复项
【问题讨论】:
-
请形成您的代码以获得更好的可见性
-
你想比较什么?
标签: javascript arrays