EN
TypeScript - 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 TypeScript.
Quick solution:
mapName.has('key');
Practical example
In this example, we use has() method to check if Map contains the specific key.
const myMap = new Map<string, string>([
['key1', 'value1'],
['key2', 'value2'],
['key3', 'value3'],
]);
console.log(myMap.has('key1')); // true
console.log(myMap.has('key4')); // false
Output:
true
false