Languages
[Edit]
EN

TypeScript - check if map contains key

0 points
Created by:
Brandy-Mccabe
754

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
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join