JavaScript Array reduceRight() Method

Beginner
⏱️ 8 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Right → left

What You’ll Learn

reduceRight() is the mirror of reduce(): it folds an array from right to left into one value. This tutorial covers syntax, when order changes the result, reversing arrays, flattening with different element order, and comparison with reduce().

01

Syntax

reduceRight(fn)

02

Direction

End → start

03

Accumulator

Same rules

04

Order

Can matter

05

vs reduce

Left vs right

06

ES5

Wide support

Introduction

You already know reduce() walks the array from index 0 upward. reduceRight() starts at the last index and moves toward 0. The callback signature and accumulator pattern are identical—only the traversal direction changes.

For addition or multiplication, direction often does not matter. For subtraction, string building, or assembling arrays in reverse order, reduceRight() gives different (and intentional) results.

Understanding the reduceRight() Method

array.reduceRight(callback, initialValue?) invokes callback(accumulator, currentValue, index, array) on each element from right to left. Each return value becomes the next accumulator; the last one is the method result.

Without initialValue, the last array element becomes the initial accumulator and the second-to-last element is processed first. On an empty array with no initial value, a TypeError is thrown.

💡
Beginner Tip

Need a reversed copy? toReversed() or [...arr].reverse() is clearer than reduceRight for most cases. Use reduceRight when the folding logic must run from the end.

📝 Syntax

General form of Array.prototype.reduceRight:

JavaScript
array.reduceRight(callback(accumulator, currentValue, index, array), initialValue)

Parameters

  • callback — returns the next accumulator (same as reduce).
  • initialValue — optional starting accumulator.

Return value

  • Final accumulator after processing from right to left.
  • Original array unchanged.

Common patterns

  • arr.reduceRight((a, n) => a + n, 0) — sum (same as reduce).
  • arr.reduceRight((a, c) => { a.push(c); return a; }, []) — reversed copy.
  • arr.reduceRight((a, c) => a + c, "") — string from right.

⚡ Quick Reference

GoalCode
Fold right to leftarr.reduceRight(fn, init)
Fold left to rightarr.reduce(fn, init)
Reverse into new arrayarr.reduceRight((a, x) => { a.push(x); return a; }, [])
Empty + no initTypeError
Mutates array?No

📋 reduceRight() vs reduce() vs reverse() vs toReversed()

Pick based on fold direction vs simply reversing element order.

reduceRight
fold ←

Custom accumulate

reduce
fold →

Default choice

reverse
mutates

In-place flip

toReversed
new array

ES2023 copy

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Basic right-to-left reduction.

Example 1 — Sum (Same Result as reduce)

Addition is order-independent, so sum matches either direction.

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

Steps run 5→4→3→2→1, but addition commutes, so the total stays 15.

Example 2 — When Order Matters: Subtraction

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

reduce starts with 10 (first element). reduceRight starts with 1 (last element). Non-commutative ops expose the direction difference.

📈 Practical Patterns

Reverse, strings, and ordered flattening.

Example 3 — Build a Reversed Copy

Push each element while walking from the end—classic reduceRight pattern.

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

Processing 5, then 4, then 3… builds the reversed array. For readability, toReversed() is often simpler today.

Example 4 — Concatenate Letters Right to Left

String order follows traversal direction.

JavaScript
const letters = ["a", "b", "c"];

const left = letters.reduce((acc, ch) => acc + ch, "");
const right = letters.reduceRight((acc, ch) => acc + ch, "");

console.log("reduce:", left);
// "abc"

console.log("reduceRight:", right);
// "cba"
Try It Yourself

How It Works

reduceRight visits c, then b, then a, producing the reversed string.

Example 5 — Flatten with Different Chunk Order

Concatenating from the right changes the final element order vs reduce.

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

const flatLeft = nested.reduce((acc, chunk) => acc.concat(chunk), []);
const flatRight = nested.reduceRight((acc, chunk) => acc.concat(chunk), []);

console.log("reduce:", flatLeft);
// [1, 2, 3, 4, 5, 6]

console.log("reduceRight:", flatRight);
// [5, 6, 3, 4, 1, 2]
Try It Yourself

How It Works

Outer chunks are merged in reverse order. Inner chunk order within each pair stays the same.

🚀 Common Use Cases

  • Right-associative math — operations that bind from the right.
  • Reverse while folding — build reversed arrays in one pass.
  • String assembly — when characters must join from the end.
  • Functional compose — mirror of left-fold pipelines (advanced).
  • Ordered merging — when chunk sequence must start at the tail.
  • Teaching direction — contrast with reduce().

🧠 How reduceRight() Runs

1

Set accumulator

Use initialValue or last element.

Start
2

Walk backward

Callback runs from last index to 0.

Reverse
3

Update accumulator

Return value feeds the next step leftward.

Fold
4

Return final value

Single result after index 0 is processed.

📝 Notes

  • Mirror of reduce() with opposite traversal.
  • Does not mutate the source array.
  • Always return the accumulator from the callback.
  • Empty array without initialValue throws TypeError.
  • For simple reversal, prefer toReversed() or reverse().
  • Commutative ops (sum, product) give same results as reduce.
  • ES5—excellent support including IE9+.

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.

Conclusion

reduceRight() folds from the last element toward the first. Use it when direction affects the outcome or when building reversed results in one pass. For most aggregations, reduce() is enough.

Next, learn reverse() to flip an array in place.

💡 Best Practices

✅ Do

  • Use when fold direction must start at the end
  • Provide initialValue for clarity and empty arrays
  • Compare with reduce when order might matter
  • Return the accumulator every callback step
  • Prefer toReversed() for simple reversal only

❌ Don’t

  • Default to reduceRight when reduce reads clearer
  • Forget subtraction/string order changes results
  • Call on empty arrays without initialValue
  • Assume it mutates the source array
  • Skip returning the accumulator inside the callback

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.reduceRight()

Fold from the last element toward the first.

5
Core concepts
02

Direction

Right to left.

Core
03

vs reduce

Order matters.

Compare
🔄 04

Reverse

Push pattern.

Pattern
+ 05

Sum

Same either way.

Commutative

❓ 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 reduceRight-style composition. Most daily tasks use reduce().
reduceRight() is ES5 (2009). It works in all modern browsers and has been supported in Internet Explorer 9+.
Did you know?

Product of [1, 2, 3, 4, 5] is 120 whether you use reduce or reduceRight, because multiplication is commutative. Subtraction and string concatenation are where direction shows up clearly.

Continue to 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.

6 people found this page helpful