Lodash _.range() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

Creates an array of numbers progressing from start up to, but not including, end. Part of Lodash Util since 0.1.0 (stable — not deprecated).

Note: JavaScript follows IEEE-754 for floats, which can produce unexpected results with fractional steps.

Syntax

Call _.range. Start with this line.

Lodash
_.range([start=0], end, [step=1])
CallWhat it does
_.range([start=0], end, [step=1])Primary signature.
_.range(...)Call the util helper.

Prefer import range from "lodash/range" when you want a smaller bundle.

Library declarations
Lodash
_.range([start=0], end, [step=1])

Parameters

ParameterDescription
startOptional. Start of the range (default 0)
endRequired. End of the range (exclusive). *With one arg, that value is end
stepOptional. Increment/decrement (default 1)

Return Value

Return ValueDescription
*Array of numbers

Lodash Examples

Example 1 — Official: One Argument

Pass only end; start defaults to 0.

Lodash
_.range(4);
// → [0, 1, 2, 3]

_.range(0);
// → []
Try It Yourself

How It Works

  1. Shorthand. One number is treated as end.
  2. Start at 0. Counts 0 … end-1.
  3. Exclusive end. 4 itself is not included.
  4. Empty. _.range(0) has nothing before the end → [].

Example 2 — Official: Start and End

Set both bounds; end stays exclusive.

Lodash
_.range(1, 5);
// → [1, 2, 3, 4]
Try It Yourself

How It Works

  1. Start. Begins at 1.
  2. Step. Default step is 1.
  3. Stop. Stops before 5.
  4. Result. [1, 2, 3, 4].

Example 3 — Official: Custom Step

Jump by a custom increment.

Lodash
_.range(0, 20, 5);
// → [0, 5, 10, 15]
Try It Yourself

How It Works

  1. Start at 0. First value is 0.
  2. Add 5. Next values are 5, 10, 15.
  3. Stop. 20 would be next but end is exclusive.
  4. Use. Handy for page sizes, ticks, and indexes.

Example 4 — Official: Negative Ranges

Count down with a negative end or a negative step.

Lodash
_.range(-4);
// → [0, -1, -2, -3]

_.range(0, -4, -1);
// → [0, -1, -2, -3]
Try It Yourself

How It Works

  1. One negative arg. Lodash uses step -1 toward that end.
  2. Explicit step. _.range(0, -4, -1) does the same clearly.
  3. Exclusive end. -4 is not included.
  4. Same list. Both forms yield [0, -1, -2, -3].

Example 5 — Official: Step of Zero

A step of 0 repeats the start value.

Lodash
_.range(1, 4, 0);
// → [1, 1, 1]
Try It Yourself

How It Works

  1. Zero step. The value never advances.
  2. Length. Lodash still produces a length based on the range width.
  3. Result. Three copies of 1.
  4. Warning. Rarely useful — prefer a positive or negative step.

Browser & Runtime Support

_.range is a Lodash Util helper since 0.1.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.range()

Available in [email protected] full builds and the lodash/range modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 0.1+
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
_.range Lodash 0.1.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import range from "lodash/range" for smaller bundles. End is exclusive; use integer steps for predictable sequences.

Frequently Asked Questions

_.range([start=0], end, [step=1]) creates an array of numbers from start up to, but not including, end. With one argument, it ranges from 0 to that value.
No. The range is exclusive of end—same idea as Python’s range. _.range(1, 5) → [1, 2, 3, 4].
That number is treated as end, and start defaults to 0. _.range(4) → [0, 1, 2, 3]. _.range(0) → [].
Use a negative step: _.range(0, -4, -1) → [0, -1, -2, -3]. Or _.range(-4) which uses step -1 automatically.
_.range builds ascending (or step-direction) sequences from start toward end. _.rangeRight fills from the right—same values, reverse order.
Official note: JavaScript follows IEEE-754 for floats, which can produce unexpected results. Prefer integer steps when you need exact values.

Next: _.rangeRight()

Generate the same numbers as _.range, filled from right to left.

_.rangeRight() 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.

10 people found this page helpful