JavaScript Array reduceRight() Method

The JavaScript Array reduceRight() method executes a reducer function on each element of the array and applies it against an accumulator.

The reduceRight() method reduces the given array elements into a single value by executing a reducer function. The reducer() function is applied against the accumulator and reduces all the elements from right to left.

Javascript array reduceRight() method applies a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value


array.reduceRight(function(total, currentValue, currentIndex, arr), initialValue)


callback: It is the callback function that executes over each array element. It undertakes the following arguments:

  1. accumulator: It accumulates the initialValue or previously returned values by the callback function.
  2. currentValue: It holds the current array element in process.
  3. currentIndex: It is optional. It holds the current value's index, being in process.
  4. array: It is optional. It is the source array to which the elements belong.

Example -