Map.prototype.has()
has() メソッドは、指定されたキーに対する要素が存在するかどうかを示す論理値を返します。
試してみましょう
構文
js
has(key)
引数
key-
Mapオブジェクト内に存在するかテストする要素のキーです。
返値
特定のキーに対する要素が Map オブジェクト内に存在していたら、true を返します。さもなければ、false を返します。
例
has() の使用
js
const myMap = new Map();
myMap.set("bar", "foo");
console.log(myMap.has("bar")); // true
console.log(myMap.has("baz")); // false
仕様書
| Specification |
|---|
| ECMAScript Language Specification # sec-map.prototype.has |
ブラウザーの互換性
BCD tables only load in the browser