Skip to main content

reduce()

reduces the array to a single value

reduce<A>(callback: ReduceCallBack<T, A>, acc: A): A;

Parameters:

  • callback: function - a function that will be called for each item in the array
  • acc: any - a value to be passed to the function as the initial value

Returns:

A single output value.

Example

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

Related sample: Data. Reduce

A handler function takes two parameters:

new_item(any) the initialValue, or the previously returned value of the function
item(any) the current item of a data collection