[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Set/difference [Back]  [Original]

Set.prototype.difference() - JavaScript | MDN

MDN Web Docs

View in English Always switch to English

Set.prototype.difference()

2024

20246

Set difference()

js
difference(other)

other

Set

Set other

AB={xAxB}A\setminus B = {x\in A\mid x\notin B}

A  B  A  B [A B A B ]

difference() other this Set this other

  • this other.size keys() other this other
  • this this other.has(e) e

this

difference()

<10<10

js
const odds = new Set([1, 3, 5, 7, 9]);
const squares = new Set([1, 4, 9]);
console.log(odds.difference(squares)); // Set(3) { 3, 5, 7 }

ECMAScript 2027 LanguageSpecification
# sec-set.prototype.difference


Web Proxy Viewer  |  New URL  |  Original Page