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 September 2015.

WeakSet인스턴스의 has() 메서드는 어떤 객체가 이 WeakSet에 있는지 여부를 가리키는 부울을 반환합니다.

시도해보기

const weakset1 = new WeakSet();
const object1 = {};
const object2 = {};

weakset1.add(object1);

console.log(weakset1.has(object1));
// Expected output: true

console.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® 2025 Language Specification
# sec-weakset.prototype.has

브라우저 호환성

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
has

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

같이 보기