Underscore.js _.isMap() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Object

Definition

Returns true if object is a Map (official Underscore docs). Plain objects, arrays, Set, and WeakMap return false.

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

Syntax

Call _.isMap. Start with this line.

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

Parameters

ParameterDescription
objectRequired. Value to test

Return Value

Return ValueDescription
*true or false

Underscore.js Examples

Example 1 — Official Docs

new Map() passes. A plain object does not.

Underscore
_.isMap(new Map());
// → true

_.isMap({});
// → false
Try It Yourself

How It Works

  1. new Map(). Real Map instance → true.
  2. {}. Plain object → false.
  3. Job of the helper. Name the Map type before you call Map methods.
  4. Takeaway. Dictionary-like {} is not a Map.

Example 2 — Common Look-alikes

Strings, numbers, objects, and arrays fail. A Map with a key passes.

Underscore
var obj = new Map();
obj.set("a string", "value associated with 'a string'");

console.log(_.isMap("string"));   // false
console.log(_.isMap(2));          // false
console.log(_.isMap({}));         // false
console.log(_.isMap([1, 2, 3]));  // false
console.log(_.isMap(obj));        // true
Try It Yourself

How It Works

  1. Primitives. Strings and numbers fail.
  2. Containers. {} and arrays fail.
  3. Filled Map. Entries do not change the type → passes.
  4. Rule. Only real Map instances pass.

Example 3 — Map vs Set vs WeakMap

Related collections are not Maps. Only Map passes.

Underscore
console.log(_.isMap(new Map()));      // true
console.log(_.isMap(new Set()));      // false
console.log(_.isMap(new WeakMap()));  // false
Try It Yourself

How It Works

  1. Map. Exact type match → true.
  2. Set. Different collection → false.
  3. WeakMap. Related, but not a Map → false.
  4. Pick the helper. Use _.isWeakMap or _.isSet for those types.

Example 4 — Empty vs Filled

Empty Maps and Maps with entries both pass. Size is separate.

Underscore
var empty = new Map();
var filled = new Map([["moe", 1], ["larry", 2]]);

console.log(_.isMap(empty));   // true
console.log(_.isMap(filled));  // true
console.log(empty.size, filled.size); // 0 2
Try It Yourself

How It Works

  1. Empty. Still a Map → passes.
  2. Filled. Entries do not change the type → passes.
  3. size. Separate from the type check.
  4. Takeaway. isMap answers type, not emptiness.

Browser & Runtime Support

_.isMap ships with Underscore.js from 1.9.0. It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore. The host must also support ES2015 Map.

✓ Stable · Underscore 1.9.0+

_.isMap()

Available since [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded and Map exists.

100% With Underscore 1.9+
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
_.isMap Underscore 1.9.0+

Bottom line: Safe for production once Underscore ≥ 1.9.0 is loaded and the runtime supports Map. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.isMap(object) returns true only when the value is a Map — new Map() or a Map that already has entries. Strings, numbers, plain objects, arrays, Set, WeakMap, null, and undefined return false.
_.isMap(new Map()) returns true. The docs pick a real Map instance on purpose: that is the type the helper looks for.
No. {} is a dictionary-like object, but it is not a Map. Underscore's tests say an object is not a map. Only values tagged [object Map] pass.
No. Underscore's tests say a set is not a map and a weakmap is not a map. Use the matching helper for each collection type.
typeof new Map() is "object", so typeof is too broad. instanceof Map usually agrees in the same window. Underscore uses the [object Map] tag, which is more consistent across iframes than instanceof.
No. It is a stable Underscore helper added in version 1.9.0. Use it to decide whether a value is a Map before you call set, get, or has.

Next: _.isWeakMap()

Detect WeakMap instances — the next collection type check.

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