Map.prototype.has()

Returns whether a key exists in a Map.

Since ES2015 (ES6) Spec ↗

Syntax

map.has(key)

Returns

boolean — `true` if the key is present.

Examples

const m = new Map([["a", 1]]);
console.log(m.has("a"));
console.log(m.has("b"));
Output
true
false
const m = new Map();
m.set("k", undefined);
console.log(m.has("k"));
Output
true

Notes

- Distinguishes a key whose value is `undefined` from a missing key. - Uses SameValueZero equality for keys.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 13
safari 8
edge 12
node 0.12

See also