JavaScript – Get Value for Specific Key in Map
To get value for a specific key in Map in JavaScript, call get() method on this Map and pass the specific key as argument. get() method returns the corresponding value for given key, if present. If the specified key is not present, then get() returns undefined.
Syntax
The syntax to get the value for a specific key in a Map map
using get) method is
map.get(key)
ADVERTISEMENT
Examples
In the following example, we get the value for key 'a'
using get() method.
index.html
Now, let us try to get the value for a key that is not present.
index.html
Conclusion
In this JavaScript Tutorial, we learned how to get the value for a specific key in a Map in JavaScript using get() method, with examples.