reduce

processes each member of the array and returns a single output value

void reduce(function callback,any initialValue);
callbackfunctiona function that will be executed on each element in the array
initialValueanythe value to be used as the first param to the first call of the callback

Example

// processes each item in data collection and returns the total size
var totalSize = vault.data.reduce(function(total, item){
        return total + item.size;
},0);

Details

The callback function may have up to three parameters:

  • accumulator - accumulates the callback's return values. It is the accumulated value previously returned in the last call of the callback, or the initialValue, if any.
  • currentValue - the current element being processed in the array.
  • currentIndex - optional, the index of the current element being processed in the array. Starts from 0.
Back to top