JavaScript (ES2026) reference · Array Methods
JavaScript Array reduceRight() Method
Like reduce(), but processes the array from the last element to the first.
JavaScript (ES2026) Since ES5
Syntax
array.reduceRight(callbackFn, initialValue)
Parameters
| Parameter | Description |
|---|---|
callbackFn |
Called with (accumulator, element, index, array). |
initialValue optional |
The starting accumulator. |
Return value
The final accumulator value.
Examples
console.log(["a", "b", "c"].reduceRight((acc, x) => acc + x, ""));
Output
cba
const compose = (...fns) => (x) => fns.reduceRight((v, f) => f(v), x);
const inc = (n) => n + 1, double = (n) => n * 2;
console.log(compose(inc, double)(5)); // inc(double(5))
Output
11
Version history
| Version | Change |
|---|---|
| JavaScript ES5 | Added |
Related
array.reduce()· Reduce the array to a single value by running a reducer function on each element, carrying an accumulator along.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial