Baseline Widely available
The get()
method of WeakMap
instances returns a specified element from this WeakMap
.
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, 42);
console.log(weakmap1.get(object1));
// Expected output: 42
console.log(weakmap1.get(object2));
// Expected output: undefined
Syntax Parameters
key
The key of the element to return from the WeakMap
object.
The element associated with the specified key in the WeakMap
object. If the key can't be found, undefined
is returned. Always returns undefined
if key
is not an object or a non-registered symbol.
const wm = new WeakMap();
wm.set(window, "foo");
wm.get(window); // Returns "foo".
wm.get("baz"); // Returns undefined.
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4