JavaScript Array reduceRight() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

Array.prototype.reduceRight(callback, initialValue?) folds an array into one value by walking right to left (last index → 0). Same accumulator pattern as reduce() — only the direction changes. It does not mutate the source array.

Remember
array.reduceRight(callback, initialValue?)

reduce()       → left to right  (index 0 → end)
reduceRight()  → right to left  (end → index 0)

sum / product  → usually same either way
subtract / join → order can change the result

empty array + no initialValue → TypeError

Syntax

Call array.reduceRight. Start with this line.

JavaScript
array.reduceRight(fn, init?)
CallWhat it does
array.reduceRight(fn, init?)Primary signature.
array.reduceRight(...)Call with the arguments your case needs.

Built into JavaScript. Call reduceRight(...) on an array instance — no import required.

Library declarations
JavaScript
array.reduceRight(fn, init?)

Parameters

ParameterDescription
ArrayRequired. Values to fold (read-only)
callbackRequired. Returns the next accumulator each step
initialValueOptional. Starting accumulator; avoids empty-array errors

Return Value

Return ValueDescription
*The value returned by array.reduceRight().

JavaScript Examples

Example 1 — Sum from the Right

Fold numbers with reduceRight and an initialValue of 0.

JavaScript
const numbers = [1, 2, 3, 4, 5];

const sum = numbers.reduceRight((acc, num) => acc + num, 0);

console.log(sum);
// 15
Try It Yourself

How It Works

  1. Start at zero. initialValue 0 is the first accumulator.
  2. Walk right to left. Steps visit 5, then 4, then 3, then 2, then 1.
  3. Add each value. Because addition commutes, the total is still 15 — same as reduce.
  4. Source untouched. numbers stays [1, 2, 3, 4, 5].

Example 2 — When Order Matters

Compare left-to-right vs right-to-left subtraction without initialValue.

JavaScript
const nums = [10, 2, 1];

const fromLeft = nums.reduce((acc, n) => acc - n);
// 10 - 2 - 1 = 7

const fromRight = nums.reduceRight((acc, n) => acc - n);
// 1 - 2 - 10 = -11

console.log("reduce:", fromLeft);
console.log("reduceRight:", fromRight);
Try It Yourself

How It Works

  1. No initial value. Each method uses an end element as the starting accumulator.
  2. reduce starts left. Acc = 10, then 10 - 2 - 1 → 7.
  3. reduceRight starts right. Acc = 1, then 1 - 2 - 10 → -11.
  4. Takeaway. Non-commutative ops expose direction — that is why reduceRight exists.

Example 3 — Build a Reversed Copy

Push each element while walking from the end to build a new reversed array.

JavaScript
const numbers = [1, 2, 3, 4, 5];

const reversed = numbers.reduceRight((acc, num) => {
  acc.push(num);
  return acc;
}, []);

console.log(reversed);
// [5, 4, 3, 2, 1]
console.log(numbers);
// [1, 2, 3, 4, 5] — unchanged
Try It Yourself

How It Works

  1. Empty seed. [] is the starting accumulator.
  2. Visit from the end. First push 5, then 4, then 3, and so on.
  3. Return the array. Each step must return acc so the next call keeps the same list.
  4. Clarity tip. For reverse-only needs, toReversed() or a copy + reverse() is often simpler.

Browser & Runtime Support

Array.prototype.reduceRight() has been available since ES5 (2009), alongside reduce().

✓ Baseline · ES5

Array.prototype.reduceRight()

Supported in Chrome 3+, Firefox 3+, Safari 4+, Edge (all versions), IE 9+, and all modern Node.js versions.

99% Universal support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.reduceRight() Excellent

Bottom line: Safe to use everywhere except very old IE8 environments. No polyfill needed for modern projects.

Frequently Asked Questions

reduceRight() works like reduce(), but walks the array from the last element toward the first. The callback still receives an accumulator and current value; the final accumulator is returned.
reduce() folds left to right; reduceRight() folds right to left. For commutative operations like sum, results match. For order-sensitive work like subtraction or building strings, results can differ.
No. reduceRight() only reads the array. Your callback may mutate objects stored in the accumulator if you choose to.
Same as reduce: optional starting accumulator. Without it on an empty array, reduceRight throws TypeError. Provide one for predictable behavior.
Use reduceRight when processing order must start at the end—reversing into a new array, right-associative math, or mirroring right-fold composition. Most daily tasks use reduce().
reduceRight() is ES5 (2009). It works in all modern browsers and has been supported in Internet Explorer 9+.

Next: reverse()

Learn how to reverse the order of elements in an array in place.

reverse() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful