All Components

aggregateBy

Applies the specified AggregateDescriptor(s) to the data.

const data = [
   { unitPrice: 23, unitsInStock: 21 },
   { unitPrice: 10, unitsInStock: 12 },
   { unitPrice: 20, unitsInStock: 33 }
];

const result = aggregateBy(data, [
  { aggregate: "sum", field: "unitPrice" },
  { aggregate: "sum", field: "unitsInStock" }
]);

//output:
// {
//    "unitPrice": {
//       "sum": 53
//     },
//     "unitsInStock": {
//       "sum": 66
//     }
// }
In this article