Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
Since June 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Set 인스턴스의 difference() 메서드는 집합을 받아서 이 집합에는 있지만 주어진 집합에는 없는 요소를 포함하는 새로운 집합을 반환합니다.
이 집합에는 있지만 other 집합에는 없는 요소를 포함하는 새 Set 객체입니다.
수학적 표기법에서 차집합(difference)는 다음과 같이 정의됩니다.
A∖B={x∊A∣x∉B}A\setminus B = {x\in A\mid x\notin B}벤 다이어그램을 사용하자면
difference()는 유사 집합객체를 other 매개변수로 받습니다. 사용자 코드를 호출하지 않고 this에 저장된 기본 데이터를 직접 검색하기 때문에 실제 Set 인스턴스가 되기 위해 this가 필요합니다. 그런 다음 동작은 this와 other의 크기에 따라 달라집니다.
반환된 집합의 요소 순서는 this와 동일합니다.
아래 예제는 홀수 집합(<10)과 완전 제곱 집합(<10)의 차이를 계산하는 예제입니다. 결과는 완전 제곱이 아닌 홀수 집합입니다.
| ECMAScript® 2027 Language Specification # sec-set.prototype.difference |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2024년 3월 21일 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.