JavaScript Map has()
- Previous page groupBy()
- Next page keys()
- Go up one level JavaScript Map Referentiemanual
Definition and usage
has()
The method is used to check if a key exists in the Map, and returns true if it does.
Instance
Example 1
// Create a Map const fruits = new Map([ ["apples", 500], ["bananas", 300], ["oranges", 200] ]); // Is there "apples" in the Map? fruits.has("apples");
Example 2
Try the following operations:
fruits.delete("apples"); fruits.has("apples");
Syntax
map.has(value)Parameter
Parameter | Description |
---|---|
value | Required. The key to check. |
Return value
Type | Description |
---|---|
Boolean | Returns true if the key exists, otherwise returns false. |
Browser support
map.has()
Is a feature of ECMAScript6 (ES6).
Starting from June 2017, all modern browsers support ES6 (JavaScript 2015):
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
2016 May | 2017 April | 2017 June | September 2016 | June 2016 |
map.has()
Not supported in Internet Explorer.
- Previous page groupBy()
- Next page keys()
- Go up one level JavaScript Map Referentiemanual