Map.prototype.has()
Returns whether a key exists in a Map.
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
| Environment | Since version |
|---|---|
| chrome | 38 |
| firefox | 13 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |