Lodash _.isMap() method

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

What you’ll learn

  • How _.isMap(value) distinguishes real Map instances from look-alikes.
  • Why WeakMap, POJOs, and other collections fail even when they feel similar.
  • How lodash picks Node’s native probe versus tag-based detection in browsers.
  • When instanceof Map alone might mislead across realms—and lodash helps.

Prerequisites

You have created a new Map() before and know it differs from plain objects.

  • You understand ES2015 collections (Map, Set) at a basic level.
  • Try-it labs load lodash from the CDN (modern browsers).

Overview

Use _.isMap inside serializers, middleware normalizers, or deep-clone utilities whenever you branch on keyed insertion order semantics guaranteed by Map—not ordinary objects.

Real Maps

Accepts empty or populated Map instances from modern engines.

Engine-aware

Node prefers util.types.isMap; browsers fall back to tag detection.

WeakMap out

Non-enumerable weak-key semantics remain excluded—by design.

Syntax

javascript
_.isMap(value)
  • value: any value to test.
  • Returns: true if value is classified as a Map; otherwise false.
1

Empty and populated Map instances

Fresh maps and maps built from iterables both identify as Maps.

javascript
import isMap from "lodash/isMap";

console.log(
  "emptyMap: " + isMap(new Map()) + "\n" +                    // true
  "withPairs: " + isMap(new Map([["key", 42]]))              // true
);
Try it Yourself
2

WeakMap, plain objects, and arrays

Different builtins and POJOs do not share the Map brand.

javascript
import isMap from "lodash/isMap";

console.log(
  "weakMap: " + isMap(new WeakMap()) + "\n" +       // false
  "plainObj: " + isMap({ a: 1 }) + "\n" +           // false
  "array: " + isMap([["x", 1]])                   // false (array of pairs, not Map)
);
Try it Yourself
3

Map subclasses versus Set

Extending Map preserves branding; Set is still a different collection.

javascript
import isMap from "lodash/isMap";

class TaggedMap extends Map {}

console.log(
  "subclass: " + isMap(new TaggedMap()) + "\n" +   // true
  "set: " + isMap(new Set())                     // false
);
Try it Yourself

📋 _.isMap vs related checks

APIBehavior
_.isMap(x)True for Map instances (tag/native probe); false for WeakMap.
x instanceof MapUsually aligned in one realm; can fail across iframes—lodash detection is more portable.
_.isPlainObject(x)Detects literal object prototypes—orthogonal to Map branding.
_.isSet(x)Companion helper for unordered unique-value collections.

Pitfalls to avoid

JSON

Serialization round-trips

JSON.stringify does not preserve Maps by default—revived data usually becomes plain objects.

Interop

Library-specific map types

Immutable.js or other wrappers may not brand as native Map—verify their own predicates.

Polyfills

Legacy environments

Ensure a faithful Map implementation exists; incomplete polyfills can confuse tagging.

❓ FAQ

WeakMap is a distinct builtin with its own internal slot branding—not interchangeable with Map semantics lodash targets.
No. Duck-typing is intentional here—lodash checks actual Map instances via engine tagging.
Yes. Instances still brand as Map objects (same prototype chain semantics engines expose).
Sets brand as [object Set]; lodash exposes _.isSet separately for keyed-vs-unordered collections.

Summary

  • Purpose: identify genuine Map instances for branching logic.
  • Remember: duck-typed objects are never Maps without engine branding.
  • Next: explore more on Lodash _.isMatch().
Did you know?

_.isMap delegates to util.types.isMap in Node when present; in browsers it falls back to isObjectLike plus Object.prototype.toString matching [object Map]—which excludes WeakMap ([object WeakMap]) and plain objects.

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