has Method (Map) (JavaScript)

 

Returns true if the map contains the specified element.

mapObj.has(key)

mapObj

Required. A Map object.

key

Required. The key of the element to test.

true if the map contains the specified element.

Example

The following example shows how to add a member to a Map and then check whether the map contains it.

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

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

// Output:
// true

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.

Show: