pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Set/has

dule">

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Set.prototype.has()

Baseline 広く利用可能

この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2015年7月以降、すべてのブラウザーで利用可能です。

has()Set インターフェイスのメソッドで、指定された値をもつ要素がこの集合内に存在するかどうかを示す論理値を返します。

試してみましょう

const set = new Set([1, 2, 3, 4, 5]);

console.log(set.has(1));
// 予想される結果: true

console.log(set.has(5));
// 予想される結果: true

console.log(set.has(6));
// 予想される結果: false

構文

js
has(value)

引数

value

この Set オブジェクトに存在するかを検査する値です。

返値

この Set オブジェクト内に指定された値をもつ要素が存在していたら true を返します。さもなければ false を返します。

has() メソッドの使用

js
const mySet = new Set();
mySet.add("foo");

console.log(mySet.has("foo")); // true
console.log(mySet.has("bar")); // false

const set = new Set();
const obj1 = { key1: 1 };
set.add(obj1);

console.log(set.has(obj1)); // true
console.log(set.has({ key1: 1 })); // オブジェクト参照が異なるため false を返す
console.log(set.add({ key1: 1 })); // set には 2 つの項目が含まれるようになる

仕様書

仕様書
ECMAScript® 2027 Language Specification
# sec-set.prototype.has

ブラウザーの互換性

関連情報

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy