Underscore.js _.isEmpty() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if collection has no elements (official Underscore docs). Array-likes use length === 0; other objects use “no enumerable own properties.”

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

Syntax

Call _.isEmpty. Start with this line.

Underscore
_.isEmpty(collection)
CallWhat it does
_.isEmpty(collection)Primary signature.
_.isEmpty(...)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
_.isEmpty(collection)

Parameters

ParameterDescription
collectionRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

A filled array is not empty. A plain object with no keys is empty.

Underscore
_.isEmpty([1, 2, 3]);
// → false

_.isEmpty({});
// → true
Try It Yourself

How It Works

  1. Filled array. length is 3 → not empty.
  2. Empty object. No own enumerable keys → empty.
  3. Different rules. Array-likes use length; plain objects use keys.
  4. Takeaway. One helper covers both shapes.

Example 2 — Arrays & Strings Use Length

Empty arrays and empty strings are empty. A space still has length 1.

Underscore
console.log(_.isEmpty([]));     // true
console.log(_.isEmpty(""));     // true
console.log(_.isEmpty("moe"));  // false
console.log(_.isEmpty(" "));    // false
Try It Yourself

How It Works

  1. [] / "". Length is 0 → empty.
  2. "moe". Length is 3 → not empty.
  3. Whitespace. " " still has length 1 → not empty.
  4. Trim first if you want to treat spaces as blank.

Example 3 — Objects Use Own Keys

Own enumerable properties decide. Inherited keys do not count.

Underscore
console.log(_.isEmpty({}));                              // true
console.log(_.isEmpty({ name: "moe" }));                   // false
console.log(_.isEmpty(Object.create({ inherited: true }))); // true
Try It Yourself

How It Works

  1. {}. No own keys → empty.
  2. { name }. Has an own key → not empty.
  3. Inherited only. Prototype keys do not count → still empty.
  4. Rule. Own enumerable properties decide for plain objects.

Example 4 — vs _.size and Falsy

An empty array is empty and truthy. 0 is empty and falsy.

Underscore
console.log(_.isEmpty([]), _.size([]), ![]);
// → true 0 false

console.log(_.isEmpty(0), Boolean(0));
// → true false
Try It Yourself

How It Works

  1. [] is empty. _.isEmpty([]) → true; _.size([]) → 0.
  2. [] is truthy. ![] is false — do not mix the two checks.
  3. 0 is empty. Numbers are always empty by Underscore’s definition.
  4. 0 is falsy. Truthiness and emptiness are different questions.

Browser & Runtime Support

_.isEmpty 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

_.isEmpty()

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
_.isEmpty 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]).

Frequently Asked Questions

_.isEmpty(collection) returns true when the value has no elements. Arrays, strings, and arguments objects are empty when length is 0. Other objects are empty when they have no enumerable own properties. null and undefined are empty.
Falsy values are false, 0, '', null, undefined, and NaN. An empty array [] is truthy in JavaScript but _.isEmpty([]) is true. Use !value for truthiness and _.isEmpty for structural emptiness.
_.size returns a count. _.isEmpty returns a boolean. For arrays, strings, and plain objects, _.isEmpty(x) is the same idea as _.size(x) === 0.
Yes. Underscore documents that primitive numbers, booleans, and symbols are always empty by this definition. So _.isEmpty(0), _.isEmpty(false), and _.isEmpty(true) are all true.
Not the way you might expect. Underscore looks at enumerable own keys, and Map/Set instances have none — so a Map with items can still look empty. Check map.size === 0 yourself.
No. It is a stable Underscore 1.x helper for asking whether a collection has no elements.

Next: _.isElement()

Detect DOM element nodes — another core Underscore type check.

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