reduce

reduces the array to a single value

void reduce(function handler,any new_item);

Parameters

handlerfunctiona function that will be called for each item in the array
new_itemanya value to be passed to the function as the initial value

Example

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

Details

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
Back to top