jPaq Docs - Array.prototype.reduce()

Quick Stats

Target Platforms:  PC (JScript) and the web (JavaScript)
Download Count:  837


Accumulate the values of an array (from left-to-right) in order to reduce it to a single value.


  1. fnCallback => Function
    The accumulator function. The first parameter is the value that has been accumulated so far. If the "initial" value is, the first parameter will be "initial" the first time this is called. Otherwise, the first value will be the value of the first element in the array. The second parameter will be the value that needs to be accumulated (or added) to the first parameter. The third will be the index of this parameter within the array. The fourth will be a reference to this array. This function should return the result of accumulating the current value (parameter two) to the previous value (parameter one).
  2. [initial] => Object
    Optional. The value of the first parameter passed to the first call to the accumulator function.


The result of accumulating all of the values within the array.

Related Examples

  1. Flatten Arrays
    One of the nice functions that is provided in Prototype is Array.prototype.flatten().  It gives you the ability to turn arrays such as…
  2. Cartesian Product
    A few weeks ago, I came across a question about finding the cartesian product of two or more arrays in JavaScript.  The following is…
  3. Reducing to the Longest Word
    Enter as many words as you want in the textbox below and then press the "Get Longest Word Length" button to see how many characters…