Skip to main content

reduce()

reduces the array to a single value

Usage

type ReduceCallBack<IDataItem, A> = (acc: A, item: IDataItem, index: number) => A;
reduce<A>(callback: ReduceCallBack<IDataItem, A>, acc: A): A;

Parameters:

  • callback: function - a function that will be called for each item in the array. The function is called with the following parameters:
    • acc: any - the initialValue, or the previously returned value of the function
    • item: IDataItem - the current item of a data collection
    • index: number - the index of the item
  • 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, IDataItem, index) {
return acc + IDataItem.value;
}, 0);

Related sample: Data. Reduce