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-get-method/ below:

JavaScript Map get() Method - GeeksforGeeks

JavaScript Map get() Method

Last Updated : 11 Jul, 2025

The Map.get() method in JavaScript is a convenient way to retrieve the value associated with a specific key in a Map object. A Map in JavaScript allows you to store key-value pairs where keys can be of any data type, making it more useful compared to objects, which only allow strings and symbols as keys.

Understanding the Map.get() Method

The Map.get() method takes a single argument—the key of the element you want to retrieve—and returns the value associated with that key. If the key does not exist in the map, the method returns undefined.

Syntax:
mapObj.get(key)
Parameter Value: Return Value:

Example 1: This example describes the Map() method to create the map object that contains the [key, value] pair to the map & displays the element that is associated with the specific key using the Map.get() method.

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

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

// Displaying the element which is associated with
// the key '0' using Map.get() method
console.log(myMap.get(0));

Output:

"GeeksforGeeks"

Example 2: This example describes the Map() method to create the map object that contains the multiple [key, value] pair to the map & displays the element that is associated with the specific key using the Map.get() method.

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 the elements which are 
//associated with the keys '0', '2' 
// and '4' using Map.get() method
console.log(myMap.get(0));
console.log(myMap.get(2));
console.log(myMap.get(4));

Output:

"GeeksforGeeks"
"for geeks"
undefined
Exceptions: 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