get Method (WeakMap) (JavaScript)

 

Returns a specified element from a WeakMap object.

weakmapObj.get(key)

weakmapObj

Required. A WeakMap object.

key

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.

Example

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(dog.breed);
document.write("<br />");
document.write(wm.get(cat) + ": ");
document.write(cat.breed);

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

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: