let data = [
{ material_no: '1001', material_name: 'Material 1', qty: 100, date: 'jan' },
{ material_no: '1001', material_name: 'Material 1', qty: 50, date: 'feb' },
{ material_no: '1002', material_name: 'Material 2', qty: 44, date: 'mar' },
{ material_no: '1003', material_name: 'Material 3', qty: 125, date: 'apr' },
{ material_no: '1002', material_name: 'Material 2', qty: 59, date: 'mar' },
{ material_no: '1004', material_name: 'Material 4', qty: 999, date: 'may' },
{ material_no: '1005', material_name: 'Material 5', qty: 80, date: 'jun' },
{ material_no: '1005', material_name: 'Material 5', qty: 66, date: 'jun' }
]
const sums = [
...data.reduce(
(map, item) => {
const { material_no: key, qty } = item;
const prev = map.get(key);
if(prev) {
prev.qty += qty
} else {
map.set(key, Object.assign({}, item))
}
return map
},
new Map()
).values()
]
console.log(sums)