A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-map-has-method/ below:

JavaScript Map has() Method - GeeksforGeeks

JavaScript Map has() Method

Last Updated : 11 Jul, 2025

The has() method in JavaScript Map returns a boolean indicating whether a specified element is present in the Map object or not. It returns true if the element is found, otherwise false.

Syntax:
mapObj.has(key)
Parameters: Return Value:

Example 1: In this example, a map object "myMap" has been created with a single [key, value] pair, and the Map.has() method is used to check whether an element with the key '0' exists in the map or not.

javascript
// creating a map object
let myMap = new Map();

// Adding [key, value] pair to the map
myMap.set(0, 'geeksforgeeks');

// displaying whether an element with 
// the key '0' exists in the map or not
// using Map.has() method
console.log(myMap.has(0));

Output:

true

Example 2: In this example, a map object "myMap" has been created with three [key, value] pairs, and the Map.has() method is used to check whether an element with the key '0' and '3' exists in the map or not.

javascript
// creating a map object
let myMap = new Map();

// Adding [key, value] pair to the map
myMap.set(0, 'geeksforgeeks');
myMap.set(1, 'is an online portal');
myMap.set(2, 'for geeks');

// displaying whether an element with the
// key '0' and '3' exists in
// the map or not using Map.has() method
console.log(myMap.has(0));
console.log(myMap.has(3));

Output:

true
false

We have a complete list of Javascript Map methods, to check those please go through this JavaScript MapComplete Reference article.

Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4