Skip to main content

reduce()

reduces the array to a single value

reduce(callback: (acc: any, item: any) => any, acc: any): any;

Parameters:

  • callback: function - a function that will be called for each item in the array. The function takes two parameters:
    • acc - the initialValue, or the previously returned value of the function
    • item - the current item of a data collection
  • acc: any - a value to be passed to the function as the initial value

Returns:

A single output value.

Example

const total = component.data.reduce(function(acc, item) {
return acc + item.value;
}, 0);

Related sample: Data. Reduce