get Method (Map) (JavaScript)

Returns a specified element from a map.

Syntax

mapObj.get(key)  

Parameters

mapObj
Required. A Map object.

key
Required. The key of an element in the Map.

Property Value/Return Value

Returns the object associated with the key. If the Map does not contain the key, this method returns an undefined value.

Example

The following example shows how to retrieve an element from a Map object.

var m = new Map();  
m.set(1, "black");  
m.set(2, "red");  
m.set("colors", 2);  

document.write(m.get(2));  

// Output:  
// red  

Requirements

Supported in the Internet Explorer 11 standards document mode. Also supported in Store apps (Windows 8.1 and Windows Phone 8.1). See Version Information.
Not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards. Not supported in Windows 8.