Open this example in the interactive library
Source code
const rows = [
{ sku: "pen", bin: "A", qty: 4 },
{ sku: "pad", bin: "B", qty: 0 },
{ sku: "pen", bin: "B", qty: 3 },
{ sku: "clip", bin: "A", qty: 9 },
];
const result = Object.fromEntries(
[...new Set(rows.map((r) => r.sku))].map((sku) => [
sku,
rows.filter((r) => r.sku === sku).reduce((sum, r) => sum + r.qty, 0),
]),
);
console.log(JSON.stringify(result, null, 2));
Sample output
{
"pen": 7,
"pad": 0,
"clip": 9
}