.has()
BrandonDusch580 total contributions
Published Dec 31, 2021Updated Jun 26, 2023
Contribute to Docs
Returns a boolean reflecting whether an entry with a given key exists in a Map
object.
Syntax
The .has()
method accepts a key
as a parameter:
map.has(key);
If the key
exists in map
, .has()
returns true
. Otherwise, it returns false
.
Example
Checking whether a key is in the fruits
Map object can be done using the .has()
method:
const fruits = new Map([['Apples', 5],['Oranges', 8],]);console.log(fruits.has('Apples')); // Output: trueconsole.log(fruits.has('Bananas')); // Output: false
The first .has()
statement checks that there are 'Apples'
in fruits
, which returns true
. The second statement finds that there are no 'Bananas'
in fruits
and false
is returned.
Codebyte Example
The following example checks if there is a known abbreviation for the strings Typescript
and Rust
.
All contributors
- BrandonDusch580 total contributions
- karel.de.smetoutlook.com7 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.