Map

Map.prototype.get

Returns the value associated to the specified key, or undefined if there is no corresponding entry

Syntax

JavaScript
map.get(key)

Parameters

ParameterTypeDescription
keyKThe key of the element to return

Return Value

The value associated with the key, or undefined

Examples

Basic Usage
const map = new Map([['name', 'Alice'], ['age', '30']]);
console.log(map.get('name')); // 'Alice'
console.log(map.get('missing')); // undefined
Practical Example
const config = new Map<string, number>([
  ['timeout', 5000],
  ['retries', 3],
]);
const timeout = config.get('timeout') ?? 3000;
console.log(timeout); // 5000
Advanced Usage
const map = new Map<object, string>();
const key = { id: 1 };
map.set(key, 'value');
console.log(map.get(key)); // 'value'
console.log(map.get({ id: 1 })); // undefined (different ref)

Understanding Map.prototype.get

The Map.prototype.get method in JavaScript returns the value associated to the specified key, or undefined if there is no corresponding entry. It belongs to the Map object and is one of the most widely used methods for working with map values in modern JavaScript and TypeScript applications.

The method signature is map.get(key). It accepts 1 parameter: key. When called, it returns the value associated with the key, or undefined. Understanding when and how to use get() helps you write more expressive, readable code.

Common use cases for Map.prototype.get include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like map-set, map-has, map-delete, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Map.prototype.get is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Map Methods

Other methods in the Map object

Related Tools

More Map Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.