What is the use of the Get method in Maps in JavaScript ?
Last Updated :
01 Feb, 2024
In JavaScript, the get()
method is used with Map objects to retrieve the value associated with a specific key. The key is passed as an argument to the get()
method, and the method returns the corresponding value if the key is found. If the key is not present in the Map, undefined
is returned.
Syntax:
myMap.get(key);
myMap
: The Map from which you want to retrieve a value.
key
: The key for which you want to get the associated value.
Example: 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
let myMap = new Map();
myMap.set(0, 'GeeksforGeeks' );
console.log(myMap.get(0));
|
Share your thoughts in the comments
Please Login to comment...