Lodash _.inRange() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Number

Definition

Checks if n is between start and up to, but not including, end — a half-open interval [start, end). Part of Lodash Number (stable since 3.3.0 — not deprecated). If end is omitted, it becomes the second argument and start defaults to 0. If start > end, the params are swapped.

Pass the numbers shown below. Check bounds and return type before you use the result.

Syntax

Call _.inRange. Start with this line.

Lodash
_.inRange(number, [start=0], end)
CallWhat it does
_.inRange(number, [start=0], end)Primary signature.

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

Library declarations
Lodash
_.inRange(number, [start=0], end)

Parameters

ParameterDescription
numberRequired. Value to check
startOptional. Inclusive start (default 0 in two-arg form)
endRequired. Exclusive end of the range

Return Value

Return ValueDescription
*true if in range, else false

Lodash Examples

Example 1 — Official: Three-Argument Range

Test a number inside [start, end).

Lodash
console.log(_.inRange(3, 2, 4)); // true
Try It Yourself

How It Works

  1. Range. Start 2 (inclusive), end 4 (exclusive).
  2. Check. 2 <= 3 < 4.
  3. Result. true — matches the official docs.
  4. Tip. Think “slice-style” ranges.

Example 2 — Official: Two-Argument Form

When end is omitted, start becomes 0.

Lodash
console.log(_.inRange(4, 8)); // true   // 0 <= 4 < 8
console.log(_.inRange(4, 2)); // false  // 0 <= 4 < 2
Try It Yourself

How It Works

  1. Rewrite. _.inRange(4, 8) → 0 <= 4 < 8.
  2. Pass. 4 is inside → true.
  3. Fail. _.inRange(4, 2) → 0 <= 4 < 2 → false.
  4. Use. Handy for “is this under N?” checks from zero.

Example 3 — Official: End Is Exclusive

The end value itself is outside the range.

Lodash
console.log(_.inRange(2, 2));    // false
console.log(_.inRange(2, 0, 2)); // false
console.log(_.inRange(1, 0, 2)); // true
Try It Yourself

How It Works

  1. Rule. Need number < end, not <=.
  2. Equal end. 2 is not less than 2 → false.
  3. Inside. 1 in [0, 2) → true.
  4. Contrast. _.clamp treats both bounds as inclusive.

Example 4 — Official: Floating-Point Values

Decimals work the same way.

Lodash
console.log(_.inRange(1.2, 2)); // true   // 0 <= 1.2 < 2
console.log(_.inRange(5.2, 4)); // false  // 0 <= 5.2 < 4
Try It Yourself

How It Works

  1. Two-arg. Start defaults to 0.
  2. Pass. 1.2 is under 2.
  3. Fail. 5.2 is not under 4.
  4. Docs. Matches the official float examples.

Example 5 — Official: Negative Range (Auto-Swap)

When start > end, Lodash swaps them.

Lodash
console.log(_.inRange(-3, -2, -6)); // true
// after swap: -6 <= -3 < -2
Try It Yourself

How It Works

  1. Args. Written as (-3, -2, -6).
  2. Swap. Becomes interval [-6, -2).
  3. Check. -3 is inside → true.
  4. Note. _.clamp does not swap bounds this way.

Browser & Runtime Support

_.inRange is a Lodash Number helper available since 3.3.0. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Native equivalents use a comparison like start <= n && n < end (after handling defaults and swaps yourself).

✓ Stable · Lodash 4.x

_.inRange()

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

100% With Lodash 4.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
_.inRange Since 3.3.0

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import inRange from "lodash/inRange" for smaller builds. Remember: end is exclusive.

Frequently Asked Questions

_.inRange(number, start, end) returns true when number is between start and up to, but not including, end. Official: _.inRange(3, 2, 4) → true.
Exclusive. After any swap, the test is start <= number < end — like array.slice(start, end).
If end is omitted, Lodash sets end to the second argument and start to 0. So _.inRange(4, 8) checks 0 <= 4 < 8 → true.
Lodash swaps them to support negative ranges. Official: _.inRange(-3, -2, -6) → true after treating the interval as [-6, -2).
inRange returns a boolean membership test on a half-open interval. clamp returns a number forced into inclusive bounds and does not auto-swap reversed bounds.
Use import inRange from "lodash/inRange" or require("lodash/inRange") so bundlers can tree-shake. Full build: import _ from "lodash" then _.inRange.

Next: _.random()

Generate a random number within a lower/upper range.

_.random() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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