gpt4 book ai didi

javascript - ES6实现Group By和SUM

转载 作者:行者123 更新时间:2023-11-30 08:23:37 24 4
gpt4 key购买 nike

<分区>

我有一组具有这些属性的对象:material_no、material_name、qty。

let data = [
{ material_no: '1001', material_name: 'Material 1', qty: 100 },
{ material_no: '1001', material_name: 'Material 1', qty: 50 },
{ material_no: '1002', material_name: 'Material 2', qty: 44 },
{ material_no: '1003', material_name: 'Material 3', qty: 125 },
{ material_no: '1002', material_name: 'Material 2', qty: 59 },
{ material_no: '1004', material_name: 'Material 4', qty: 999 },
{ material_no: '1005', material_name: 'Material 5', qty: 80 },
{ material_no: '1005', material_name: 'Material 5', qty: 66 }
]

如何返回按 Material 编号/ Material 名称分组的对象数组以及具有相同 Material 编号/ Material 名称的数量总和?

[
{ material_no: '1001', material_name: 'Material 1', qty: 150 },
{ material_no: '1002', material_name: 'Material 2', qty: 103 },
{ material_no: '1003', material_name: 'Material 3', qty: 125 },
{ material_no: '1004', material_name: 'Material 4', qty: 999 },
{ material_no: '1005', material_name: 'Material 5', qty: 146 }
]

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com