Get to know MDN better
このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
intersection() は Set インスタンスのメソッドで、集合を受け取り、この Set と指定された集合の両方にある要素の入った新しい Set を返します。
新しい Set オブジェクトで、この Set と other の集合の両方にある要素が入ったものです。
数学的な記法では、交差 (intersection) は次のように定義されます。
A∩B={x∊A∣x∊B}A\cap B = \{x\in A\mid x\in B\}ベン図を使うとこうなります。
intersection() は、Set 風オブジェクトを other 引数として受け入れます。this は、ユーザーコードを呼び出すことなく、this オブジェクトに格納されているデータに直接アクセスするため、実際の Set インスタンスであることが要求されます。その後、その動作は this と other のサイズに依存します。
この実装により、intersection() の実行効率は、this と other のうち小さい方のセットのサイズにほぼ依存します(Set が指数時間でアクセスできると仮定した場合)。返される Set の要素の順序は、this と other のうち小さい方のセットの順序と同じです。
次の例では、奇数(10 未満)と完全平方(10 未満)の集合の共通部分を計算します。結果は、完全平方である奇数の集合となります。
| ECMAScript® 2027 Language Specification # sec-set.prototype.intersection |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月18日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.