Lodash _.isLength() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Lang

Definition

Checks if value is a valid array-like length. Loosely based on ECMAScript ToLength. Part of Lodash Lang since 4.0.0 (stable — not deprecated).

Pass the value you want to inspect or convert. Read the return type carefully before you use the result.

Syntax

Call _.isLength. Start with this line.

Lodash
_.isLength(value)
CallWhat it does
_.isLength(value)Primary signature.

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

Library declarations
Lodash
_.isLength(value)

Parameters

ParameterDescription
valueRequired. The value to check

Return Value

Return ValueDescription
*true if valid length, else false

Lodash Examples

Example 1 — Official: 3

A small non-negative integer is a valid length.

Lodash
_.isLength(3);
// → true
Try It Yourself

How It Works

  1. Input. Official sample: the number 3.
  2. Type. typeof 3 === "number".
  3. Shape. Non-negative, whole, within MAX_SAFE_INTEGER.
  4. Result. true — valid array-like length.

Example 2 — Official: Number.MIN_VALUE

Tiny positive floats are not whole lengths.

Lodash
_.isLength(Number.MIN_VALUE);
// → false
Try It Yourself

How It Works

  1. Value. Number.MIN_VALUE is the smallest positive float (~5e-324).
  2. Integer test. value % 1 !== 0 — not whole.
  3. Result. false.
  4. Tip. Do not confuse MIN_VALUE with a minimum length of zero.

Example 3 — Official: Infinity

Non-finite numbers cannot be array lengths.

Lodash
_.isLength(Infinity);
// → false
Try It Yourself

How It Works

  1. Input. Official sample: Infinity.
  2. Bound. It exceeds MAX_SAFE_INTEGER and is not a usable index count.
  3. Result. false.
  4. Same idea. -Infinity and NaN also fail.

Example 4 — Official: string "3"

Numeric strings look like lengths but fail the type gate.

Lodash
_.isLength('3');
// → false

_.isLength(Number('3'));
// → true   // after parsing
Try It Yourself

How It Works

  1. String. typeof '3' === "string" → immediate fail.
  2. Parse. Number('3') yields the number 3.
  3. Recheck. That number is a valid length → true.
  4. Forms / APIs. Always coerce query params before validating.

Example 5 — Zero and MAX_SAFE_INTEGER

Empty lengths and the inclusive safe ceiling both pass; one past fails.

Lodash
_.isLength(0);                        // → true
_.isLength(Number.MAX_SAFE_INTEGER);  // → true
_.isLength(Number.MAX_SAFE_INTEGER + 1); // → false
_.isLength(-1);                       // → false
Try It Yourself

How It Works

  1. Zero. Empty collections use length 0 → allowed.
  2. Ceiling. MAX_SAFE_INTEGER is the inclusive upper bound.
  3. Past safe. One larger fails even if it “looks” whole in math.
  4. Negatives. -1 is an integer but never a length.

Browser & Runtime Support

_.isLength is a Lodash Lang helper (available since 4.0.0, stable in 4.x). It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.0.0+

_.isLength()

Available in [email protected] full builds and the lodash/isLength 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
_.isLength Lodash 4.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import isLength from "lodash/isLength" for smaller builds. Native alternative for a similar idea: Number.isSafeInteger(n) && n >= 0.

Frequently Asked Questions

_.isLength(value) returns true if value is a valid array-like length: a number that is non-negative, an integer, and ≤ Number.MAX_SAFE_INTEGER (9007199254740991).
No. _.isInteger allows negatives (for example -7). _.isLength only accepts values > -1 and also caps at MAX_SAFE_INTEGER.
The value must be a number type first. Numeric strings fail even if they look like lengths — parse with Number(...) or _.toNumber before checking.
Yes. 0 is a valid length for empty collections because the check is value > -1, not value > 0.
Both return false. Infinity is not finite; MIN_VALUE is a tiny positive float, not an integer length.
Use import isLength from "lodash/isLength" or require("lodash/isLength"). Full build: import _ from "lodash" then _.isLength.

Next: _.isMap()

Check whether a value is classified as a Map object.

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