Lodash _.rangeRight() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll use Lodash’s _.rangeRight() to build number arrays in reverse order—the mirror of _.range() with the same start, end, and step rules.

01

Core Syntax

_.rangeRight(start, end, step)

02

Same args

As _.range.

03

Reverse order

High → low in array.

04

Reverse indexes

Walk arrays backward.

05

Not countdown

Use range + negative step.

06

Exclusive end

Same as range.

What Is _.rangeRight()?

_.rangeRight() is the reversed sibling of _.range(). Lodash first computes the same progression—same start, end (exclusive), and step—then returns the numbers in opposite array order. It does not automatically count down from start to end unless that is what reversing _.range’s output produces.

💡
Beginner tip — reverse order ≠ countdown

_.rangeRight(10, 0) is [1, 2, …, 10], not [10, 9, …, 1]. For a literal countdown sequence, use _.range(10, 0, -1).

The classic use case is reverse iteration: _.rangeRight(array.length) yields indexes from last to first so you can walk an array backward without manual index math.

📝 Syntax

Identical signature to _.range():

javascript
_.rangeRight([start = 0], end, [step = 1 or -1])

Syntax Rules

  • Same parameters as range — one arg = exclusive end with start 0; end is never included.
  • Reverse output — mentally: _.range(...).reverse() (Lodash implements this efficiently).
  • One argument_.rangeRight(5)[4, 3, 2, 1, 0].
  • Countdown values — use _.range(start, end, -step), not rangeRight alone.
  • Index helper_.rangeRight(n) for indexes n-1 down to 0.
javascript
import rangeRight from "lodash/rangeRight";



rangeRight(1, 5);

// [4, 3, 2, 1]

⚡ Quick Reference

TaskCode patternResult
Reverse 0..n−1_.rangeRight(n)[n−1 … 0]
Reverse 1..4_.rangeRight(1, 5)[4, 3, 2, 1]
Step, reversed_.rangeRight(1, 10, 2)[9, 7, 5, 3, 1]
Reverse indexes_.rangeRight(arr.length)last → 0
Countdown 10→1_.range(10, 0, -1)Not rangeRight
Ascending order_.range(...)Low → high
Returns
Array

Reversed nums

Args
= range

Same rules

Order
High → low

In array

Category
Util

Sequence

🧰 Parameters

Same parameters as _.range()—only the output order differs:

start Optional

First value of the underlying progression. Defaults to 0 when only end is passed.

_.rangeRight(2, 5)
end Required*

Exclusive stop boundary—the end value is not in the result (before reversing).

_.rangeRight(1, 5)
step Optional

Stride between values in the underlying range; output is that sequence reversed.

_.rangeRight(0, 20, 5)
return Array

Numbers in reverse order of what _.range(same args) would return.

[4, 3, 2, 1]

Mental model: _.rangeRight(a, b, c)_.range(a, b, c).reverse() for typical numeric inputs.

Examples Gallery

Practical _.rangeRight() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Same math as range—numbers stored in reverse order.

Example 1 — Step sequence, reversed

_.range(1, 10, 2) is [1, 3, 5, 7, 9]; rangeRight flips it.

javascript
console.log(_.rangeRight(1, 10, 2));

console.log(_.range(1, 10, 2));

// [9, 7, 5, 3, 1]

// [1, 3, 5, 7, 9]
Try It Yourself

How It Works

Include 1 at the end—the old reference omitted it. Both arrays contain the same numeric set; only order differs.

Example 2 — Two-argument form

Reverse of [1, 2, 3, 4].

javascript
console.log(_.rangeRight(1, 5));

console.log(_.rangeRight(0, 10, 3));

// [4, 3, 2, 1]

// [9, 6, 3, 0]
Try It Yourself

How It Works

End remains exclusive before the reverse—5 and 10 never appear.

Example 3 — Official Lodash demos

Documented one-arg and signed-end cases.

javascript
console.log(_.rangeRight(4));

console.log(_.rangeRight(-4));

console.log(_.rangeRight(0, 20, 5));

console.log(_.rangeRight(0, -4, -1));

// [3, 2, 1, 0]

// [-3, -2, -1, 0]

// [15, 10, 5, 0]

// [-3, -2, -1, 0]

How It Works

Each line is the reverse of the matching _.range(...) call with the same arguments.

📈 Practical Patterns

Reverse iteration and the countdown distinction.

Example 4 — Iterate an array backward

The most common real-world use—reverse indexes without i-- loops.

javascript
const letters = ["a", "b", "c", "d", "e"];



_.rangeRight(letters.length).forEach((index) => {

  console.log(letters[index]);

});

// e, d, c, b, a
Try It Yourself

How It Works

_.rangeRight(5)[4, 3, 2, 1, 0]. Each index picks the next element from the end.

Example 5 — Countdown: rangeRight vs range

Do not use rangeRight for a 10→1 countdown—use negative step on range instead.

javascript
// Wrong tool for "10, 9, …, 1" display:

console.log(_.rangeRight(10, 0));

// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]



// Correct countdown sequence:

console.log(_.range(10, 0, -1));

// [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]

How It Works

rangeRight reverses range’s output; range with -1 step builds descending values directly.

🚀 Beyond the Basics

Side-by-side with range and native reverse.

Example 6 — rangeRight vs range vs reverse

Three ways to get related results—pick by intent.

javascript
const args = [2, 5];



console.log(_.rangeRight(...args));

console.log(_.range(...args).reverse());

console.log(_.range(...args));

// [4, 3, 2]  — rangeRight

// [4, 3, 2]  — manual reverse (same result)

// [2, 3, 4]  — ascending range

When to use which

Prefer rangeRight for clarity when you want reversed order; use range when ascending; use range + negative step for true descending values.

🧠 How _.rangeRight() Works

1

Normalize args

Same rules as range—one arg becomes end, infer step sign from direction.

Setup
2

Build progression

Compute the arithmetic sequence up to (but not including) end.

Range math
3

Reverse order

Return values from last generated to first—high index values appear first.

Flip
=

Reversed array

Same numbers as range, stored from end value toward start value.

📝 Notes

  • rangeRight reverses array order, not necessarily numeric descent—read the countdown example carefully.
  • _.rangeRight(10, 0) is [1…10]; _.range(10, 0, -1) is [10…1].
  • Old tutorials often show wrong outputs for step and edge cases—always verify against _.range(...).
  • For backward array walks, _.rangeRight(arr.length) is cleaner than manual decrement loops.
  • End is exclusive—same rule as _.range().
  • Next in the series: _.runInContext()—isolated Lodash copies for plugins.

Conclusion

_.rangeRight() is range with the result flipped—ideal for reverse indexes and any time you want the same numeric progression stored high-to-low. Remember the countdown pitfall: descending values usually mean _.range with a negative step.

When in doubt, log both _.range(...) and _.rangeRight(...) side by side—the relationship clicks immediately.

💡 Best Practices

✅ Do

  • Use _.rangeRight(length) for reverse index iteration
  • Compare mentally with _.range(...).reverse()
  • Use _.range(10, 0, -1) for literal countdown sequences
  • Keep the same exclusive-end rules as range
  • Pair with forEach or for…of for readable backward walks

❌ Don’t

  • Assume rangeRight always counts down numerically
  • Trust outdated examples that omit boundary values (e.g. missing 1 in step demos)
  • Use rangeRight(10, 0) expecting [9, 8, …, 1]
  • Confuse reversed order with negative step semantics
  • Build huge ranges when you only need a simple decrement loop once

Key Takeaways

Knowledge Unlocked

Five things to remember about _.rangeRight()

Use these points when you need reversed numeric arrays.

5
Core concepts
🔄 02

Same args

As range.

Syntax
03

Reverse idx

Walk arrays.

Usage
📝 04

Countdown

Use range −step.

Pitfall
🛠 05

Exclusive end

Same rule.

Rule

❓ Frequently Asked Questions

_.rangeRight(start, end, step) builds the same arithmetic progression as _.range() with identical arguments, then returns those numbers in reverse order—last value first, first value last.
Same parameters, opposite array order. _.range(1, 5) is [1, 2, 3, 4]. _.rangeRight(1, 5) is [4, 3, 2, 1]. The numeric set is the same; only the sequence direction in the array changes.
Usually not. _.rangeRight(10, 0) yields [1, 2, …, 10], not [10, 9, …, 1]. For a high-to-low countdown, use _.range(10, 0, -1) instead.
Same rule as range: the lone value is end (exclusive), start defaults to 0. _.rangeRight(5) is [4, 3, 2, 1, 0]—the reverse of [0, 1, 2, 3, 4].
Reverse index walks: _.rangeRight(array.length) gives [n-1, …, 0] for iterating from the last element backward. Also handy when you want the same range math as range but stored high-to-low.
Exclusive—same as range. _.rangeRight(1, 5) stops before 5, producing [4, 3, 2, 1].
Did you know?

_.rangeRight(2, 5) and _.range(2, 5).reverse() both yield [4, 3, 2]—rangeRight is essentially a convenience wrapper around the same progression logic with reversed output.

Practice _.rangeRight() in the Live Editor

Try reversed step sequences, two-argument forms, and backward array iteration.

Open Try It editor →

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