get Method (WeakMap)

get Method (WeakMap) (JavaScript)


Returns a specified element from a WeakMap object.



Required. A WeakMap object.


Required. The key of an element in the WeakMap.

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

The following example shows how to retrieve members from a WeakMap object.

var dog = {
    breed: "yorkie"

var cat = {
    breed: "burmese"

var wm = new WeakMap();
wm.set(dog, "fido");
wm.set(cat, "pepper");

document.write(wm.get(dog) + ": ");
document.write("<br />");
document.write(wm.get(cat) + ": ");

// Output:
// fido: yorkie
// pepper: burmese


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.

© 2015 Microsoft