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
オブジェクトから指定された要素を返します。
試してみましょう
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
構文
wm.get(key);
引数
key
-
必須。
WeakMap
オブジェクトから返す要素のキーです。
返値
指定されたキーと関連した要素を返します。キーが WeakMap
オブジェクトに見つからない場合、 undefined
を返します。
例
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 GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
get |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- See implementation notes.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.