JavaScript Map.prototype.has() Method
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
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.
Desktop





Tablets & Mobile





