Lodash _.isEmpty() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.isEmpty(value) treats arrays, strings, buffers, and array-like values.
  • When plain objects and Map/Set instances count as empty.
  • Why null/undefined and many primitives read as empty.
  • Where lodash differs from rolling your own Object.keys checks.

Prerequisites

Comfort with JavaScript collections (arrays and strings) and plain objects.

  • You understand length for arrays/strings versus keyed properties on objects.
  • Try-it labs load lodash from the CDN.

Overview

Use _.isEmpty before rendering placeholders, enabling submit buttons, or pruning caches—anywhere “no meaningful payload yet” must be detected uniformly across arrays, maps, and POJOs.

Collections

Arrays, strings, typed buffers—lodash reads length where applicable.

Keyed data

Plain objects lose emptiness as soon as an own enumerable key appears.

Map / Set

Native maps and sets compare size against zero.

Syntax

javascript
_.isEmpty(value)
  • value: any value to test.
  • Returns: true if value is empty per lodash rules; otherwise false.
1

Arrays and strings

Zero-length collections register as empty; a populated array fails the check.

javascript
import isEmpty from "lodash/isEmpty";

console.log(
  "emptyArr: " + isEmpty([]) + "\n" +           // true
  "emptyStr: " + isEmpty("") + "\n" +           // true
  "nonEmptyArr: " + isEmpty([1])                // false
);
Try it Yourself
2

null and non-collection primitives

Lodash treats nullish values as empty; numbers and booleans fall outside collection branches and read empty too.

javascript
import isEmpty from "lodash/isEmpty";

console.log(
  "nullVal: " + isEmpty(null) + "\n" +           // true
  "primitiveNum: " + isEmpty(1) + "\n" +         // true
  "primitiveBool: " + isEmpty(false)             // true
);
Try it Yourself
3

Plain objects and Map

Keyed payloads flip false once data exists; empty maps clear via size.

javascript
import isEmpty from "lodash/isEmpty";

console.log(
  "emptyPlain: " + isEmpty({}) + "\n" +                           // true
  "hasKeys: " + isEmpty({ a: 1 }) + "\n" +                         // false
  "emptyMap: " + isEmpty(new Map())                               // true
);
Try it Yourself

📋 _.isEmpty vs related checks

APIMatches
_.isEmpty(x)Structural emptiness—collections without entries or objects without own enumerable keys.
_.isNil(x)Only null or undefined; ignores empty arrays/strings.
(x || []).length === 0Array/string-specific hack—misses objects/maps unless duplicated logic.
Object.keys(x).length === 0Plain-object oriented—throws or misbehaves on nullish values without guards.

Pitfalls to avoid

Whitespace

Strings with spaces

" " is non-empty—trim first if whitespace should collapse to empty.

Semantics

Primitives aren’t “full”

Numbers returning true surprises newcomers—pair with _.isNumber when distinguishing missing payloads.

DOM

NodeLists

Array-like DOM collections follow length; an attached-but-empty NodeList is still empty.

❓ FAQ

No. Non-empty collections can still be truthy or falsy for other reasons; _.isEmpty focuses on structural emptiness (length, size, or own enumerable keys).
Those primitives are not array-like collections in lodash's branching logic—they fall through to rules where lodash treats them as empty non-collections.
Yes. Lodash inspects the object tag and compares size to zero for native Map and Set instances.
Yes. A string containing only spaces still has length greater than zero, so _.isEmpty returns false.

Summary

  • Purpose: unify emptiness checks across arrays, strings, keyed objects, maps, and sets.
  • Remember: nullish and many primitives report empty—do not equate with user-visible “missing form data.”
  • Next: explore more on Lodash _.isEqual().
Did you know?

_.isEmpty returns true for null and undefined, zero-length arrays and strings, objects with no own enumerable keys (via iteration), and Map/Set instances whose size is 0. Many primitives—such as numbers or booleans—are treated as empty because they are not collections.

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.

6 people found this page helpful