Favorites

JavaScript Map.prototype.has() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Map.prototype.has()
JavaScript Map Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The has() method checks whether a Map contains a key.

Description

The has() method returns whether the map has an entry for the key. It's the reliable way to check, since get() returns undefined both for missing keys and for stored undefined values.

Checking with has() before get() is a common pattern for caches: if the key is there, return the stored value; otherwise compute it and set() it. Lookups are fast regardless of the map's size.

Keys are compared with the SameValueZero algorithm: primitives by value, NaN as equal to itself, and objects only when they're the same object.

Syntax

map.has(key)

Parameters

  • keyThe key to check.

Return Value

true if the key exists, otherwise false.

Example

const m = new Map([['k', undefined]]);
console.log(m.has('k'), m.get('k'));
console.log(m.has('z'));

Browser Support

The following information will show you the current browser support for the Map.prototype.has() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee