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 functionitem: IDataItem- the current item of a data collectionindex: 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