get Method (Map) (JavaScript)

Returns a specified element from a map.

mapObj.get(key)

mapObj

Required. A Map object.

key

Required. The key of an element in the Map.

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

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

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.

Show:
© 2014 Microsoft