I have an array of objects with these properties: 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 }
]
How do I return an array of objects grouped by their material_no/material_name and sum of the qty having the same material_no/material_name?
[
{ 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 }
]
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…