.get()
Published Dec 31, 2021
Contribute to Docs
Retrieves a value associated with a given key in a Map
object.
Syntax
The .get()
method accepts a key
parameter and checks it against a Map
object. If the key
exists in the map, the accosiated value is returned. If not, undefined
is returned.
map.get(key);
Example
Values are retrieved by their keys from Map
objects using the .get()
method.
const fruits = new Map([['Apples', 5],['Oranges', 8],]);console.log(fruits.get('Apples')); // Output: 5console.log(fruits.get('Oranges')); // Output: 8console.log(fruits.get('Bananas')); // Output: undefined
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.