JavaScript Checking if a key exists in a Map


Example

To check if a key exists in a Map, use the .has() method:

map.has(key);

Example:

const map = new Map([[1, 2], [3, 4]]);
console.log(map.has(1)); // true
console.log(map.has(2)); // false