This page was translated from English by the community.Learn more and join the MDN Web Docs community.
Set.prototype.has()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Set 객체의has() 메서드는이 Set 객체에 주어진 요소가 존재하는지 여부를 판별해 반환합니다.
In this article
시도해 보기
const set1 = new Set([1, 2, 3, 4, 5]);console.log(set1.has(1));// Expected output: trueconsole.log(set1.has(5));// Expected output: trueconsole.log(set1.has(6));// Expected output: false구문
js
has(value)매개변수
valueSet객체에서 존재 여부를 판별할 값.
반환 값
Set 객체에 값이 존재하면true, 아니면false.
예제
>has() 메서드 사용하기
js
const mySet = new Set();mySet.add("foo");console.log(mySet.has("foo")); // trueconsole.log(mySet.has("bar")); // falseconst set1 = new Set();const obj1 = { key1: 1 };set1.add(obj1);console.log(set1.has(obj1)); // trueconsole.log(set1.has({ key1: 1 })); // false, 형태만 같은 서로 다른 객체의 참조이기 때문console.log(set1.add({ key1: 1 })); // set1의 요소가 2개로 늘어남명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-set.prototype.has> |