Array

Array.prototype.reduceRight

Applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value

Syntax

JavaScript
array.reduceRight(callbackFn, initialValue?)

Parameters

ParameterTypeDescription
callbackFn(accumulator, currentValue, index, array) => TFunction to execute on each element
initialValueTInitial value for the accumulator

Return Value

The value resulting from the reduction

Examples

Basic Usage
const arr = [[1, 2], [3, 4], [5, 6]];
const flat = arr.reduceRight((acc, cur) => acc.concat(cur), [] as number[]);
console.log(flat); // [5, 6, 3, 4, 1, 2]
Practical Example
const pipe = [
  (x: number) => x + 1,
  (x: number) => x * 2,
  (x: number) => x - 3,
];
const result = pipe.reduceRight((val, fn) => fn(val), 5);
console.log(result); // ((5 - 3) * 2) + 1 = 5
Advanced Usage
const words = ['world', ' ', 'hello'];
const sentence = words.reduceRight((acc, w) => acc + w, '');
console.log(sentence); // 'hello world'

Understanding Array.prototype.reduceRight

The Array.prototype.reduceRight method in JavaScript applies a function against an accumulator and each value of the array (from right-to-left) to reduce it to a single value. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.

The method signature is array.reduceRight(callbackFn, initialValue?). It accepts 2 parameters: callbackFn, initialValue. When called, it returns the value resulting from the reduction. Understanding when and how to use reduceRight() helps you write more expressive, readable code.

Common use cases for Array.prototype.reduceRight include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-reduce, array-map, array-filter, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Array.prototype.reduceRight is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Array Methods

Other methods in the Array object

Related Tools

More Array Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.