WeakMap.prototype.has()
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.
has()
メソッドは、特定のキーをもつ要素が WeakMap
オブジェクト内に存在するかどうかを示す真偽値を返します。
試してみましょう
const weakmap1 = new WeakMap();
const object1 = {};
const object2 = {};
weakmap1.set(object1, "foo");
console.log(weakmap1.has(object1));
// Expected output: true
console.log(weakmap1.has(object2));
// Expected output: false
構文
ws.has(key);
引数
key
-
WeakMap
オブジェクトに存在するかテストする要素のキーです。
返値
- Boolean
-
WeakMap
オブジェクト内に特定のキーをもつ要素が存在していたらtrue
を返します。さもなければfalse
を返します。
例
has() メソッドの使用
js
var wm = new WeakMap();
wm.set(window, "foo");
wm.has(window); // true を返す
wm.has("baz"); // false を返す
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-weakmap.prototype.has |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
has |
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.