JavaScript Array.prototype.reduceRight() Method
The reduceRight() method works like reduce() but processes the array from the last element to the first.
Description
The reduceRight() method is the same as reduce(), but it walks the array from right to left. It's occasionally useful when the order matters, such as composing functions so that the last one runs first.
It takes the same callback as reduce(): the accumulator, the current element, its index and the array. With no initial value, the last element is used as the starting accumulator and the loop begins at the second-to-last element. Empty slots in sparse arrays are skipped.
For operations where order doesn't matter, such as summing numbers, reduceRight() and reduce() give the same result. It makes a difference when combining strings, building nested structures from the inside out, or composing functions, where the last function in the list should run first.
Syntax
array.reduceRight(callbackFn)
array.reduceRight(callbackFn, initialValue)Parameters
- callbackFnA function that combines the accumulator with each element, from right to left.
- initialValueOptional. The starting value of the accumulator.
Return Value
The final value of the accumulator.
Exceptions
- TypeErrorThrown if the array is empty and no
initialValueis given.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.reduceRight() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





