Underscore.js _.range() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Creates flexibly numbered lists of integers — handy for each and map loops (official Underscore docs). Stable Array helper — not deprecated.

Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.range. Start with this line.

Underscore
_.range([start], stop, [step])
CallWhat it does
_.range([start], stop, [step])Primary signature.
_.range(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.range([start], stop, [step])

Parameters

ParameterDescription
startOptional. First value (default 0)
stopRequired. Exclusive end of the sequence
stepOptional. Increment / decrement between values

Return Value

Return ValueDescription
*New array of numbers

Underscore.js Examples

Example 1 — Official: Stop Only

One argument is the exclusive stop; start defaults to 0.

Underscore
_.range(10);
// → [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Try It Yourself

How It Works

  1. One argument. Underscore treats 10 as stop.
  2. Start at 0. The first value pushed is 0.
  3. Step by 1. Default ascending step fills 1 … 9.
  4. Stop excluded. 10 is never added — length is 10.

Example 2 — Official: Start and Stop

Set both ends when you do not want to start at zero.

Underscore
_.range(1, 11);
// → [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Try It Yourself

How It Works

  1. Inclusive start. The list begins at 1.
  2. Exclusive stop. Values go up to 10, not 11.
  3. Length tip. Count = stop − start when step is 1.
  4. Use case. Page numbers, 1-based indexes, chart ticks.

Example 3 — Official: Custom Step

The third argument sets the gap between numbers.

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

How It Works

  1. Start at 0. First value is 0.
  2. Add 5 each time. Next values: 5, 10, 15, 20, 25.
  3. Hit the wall. 30 equals stop → not included.
  4. Handy for. Multiples, tick marks, every-nth indexes.

Example 4 — Official: Count Down

A negative step builds a descending sequence.

Underscore
_.range(0, -10, -1);
// → [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
Try It Yourself

How It Works

  1. Start at 0. First value is 0.
  2. Step −1. Each next value is one smaller.
  3. Stop at −10. Exclusive — -10 is not pushed.
  4. Direction. Without a negative step, a descending span would be empty or auto-step -1 depending on args — be explicit for clarity.

Browser & Runtime Support

_.range ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.range()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
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 Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]). Native alternatives include a small loop or Array.from({ length: n }, (_, i) => i).

Frequently Asked Questions

_.range([start], stop, [step]) returns a new array of numbers from start (inclusive) up to but not including stop, moving by step. Example: _.range(1, 5) returns [1, 2, 3, 4].
That value is the stop, and start defaults to 0. So _.range(4) returns [0, 1, 2, 3].
No. Stop is exclusive. _.range(0, 3) returns [0, 1, 2], not [0, 1, 2, 3].
Yes. Pass a negative step, e.g. _.range(0, -10, -1). If step is omitted and stop is before start, Underscore defaults step to -1.
When there are no steps to take — for example _.range(0), _.range(5, 5), or a step that moves away from stop.
_.range builds an array of numbers. _.times(n, iteratee) runs a function n times and collects the return values — use times when you care about the callback, range when you need the indexes.

Next: Array methods hub

Browse every Underscore.js array helper in one place.

Array methods →

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