Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Array.prototype.reduceRight

Reduces an array to one value, going from right to left.

Available since: ES5

Syntax

array.reduceRight(callbackFn, initialValue)

Parameters

ParameterTypeDescription
callbackFnFunctionA function that receives the accumulator and the current element and returns the new accumulator.
initialValueanyOptional. The starting value of the accumulator.

Return value

anyThe final accumulated value.

Examples

Joining in reverse order:

console.log(['a', 'b', 'c'].reduceRight((acc, letter) => acc + letter, ''));

Output:

cba

Notes

Works like reduce() but from the end of the array. Rarely needed — usually to compose functions right to left.

See also

In the tutorial

  • map, filter and reduce — The three main array processing methods in JavaScript: transforming, selecting and reducing to a single value.

Thanks for reading!

Donate to the site — we work hard for you.