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.
Fundamentals
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.
Foundation
📝 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.
Next in the series: _.runInContext()—isolated Lodash copies for plugins.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.rangeRight()
Use these points when you need reversed numeric arrays.
5
Core concepts
🔢01
Reverse order
Vs range.
Core
🔄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.