This page was translated from English by the community.Learn more and join the MDN Web Docs community.
WeakSet.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년 9월.
WeakSet인스턴스의has() 메서드는 어떤 객체가 이WeakSet에 있는지 여부를 가리키는 부울을 반환합니다.
In this article
시도해 보기
const weakset1 = new WeakSet();const object1 = {};const object2 = {};weakset1.add(object1);console.log(weakset1.has(object1));// Expected output: trueconsole.log(weakset1.has(object2));// Expected output: false구문
js
has(value)매개변수
value이
WeakSet에서 존재를 시험할 값
반환 값
이WeakSet에서 특정 값의 요소가 존재한다면true를 반환하며, 그렇지 않을 경우에는false를 반환합니다.value가 객체가 아니거나 혹은등록되지 않은 심볼일 경우 언제나false를 반환합니다.
예제
>has() 메서드 사용하기
js
const ws = new WeakSet();const obj = {};ws.add(window);ws.has(window); // true 반환ws.has(obj); // false 반환// 등록되지 않은 symbol 저장const sym = Symbol("foo");ws.add(sym);ws.add(Symbol.iterator);명세서
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-weakset.prototype.has> |