EN
JavaScript - check if map contains key
0
points
In this article, we would like to show you how to check if a Map contains a key using JavaScript.
Quick solution:
mapName.has('key');
Practical example
In this example, we use has() method to check if Map contains the specific key.
// ONLINE-RUNNER:browser;
const myMap = new Map([
['key1', 'value1'],
['key2', 'value2'],
['key3', 'value3'],
]);
console.log(myMap.has('key1')); // true
console.log(myMap.has('key4')); // false
Output:
true
false