WeakMap.prototype.get()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

Метод get() возвращает элемент из объекта WeakMap,

Синтаксис

wm.get(key);

Параметры

key

Обязателен. Ключ элемента, который будет возвращён из объекта WeakMap.

Возвращаемое значение

Возвращает элемент по указанному ключу или undefined, если ключ не может быть найден в объекте WeakMap.

Примеры

Использование метода get

js
var wm = new WeakMap();
wm.set(window, "foo");

wm.get(window); // Возвращает "foo".
wm.get("baz"); // Возвращает undefined.

Спецификации

Specification
ECMAScript® 2025 Language Specification
# sec-weakmap.prototype.get

Совместимость с браузерами

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
get

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

Firefox-specific notes

  • Prior to SpiderMonkey 38, this method threw a TypeError when the key parameter was not an object. However, the latest ES6 standard specifies to return undefined instead. Furthermore, WeakMap.prototype.get accepted an optional second argument as a fallback value, which is not part of the standard. Both non-standard behaviors are removed in version 38 and higher (Firefox bug 1127827).

Смотрите также