← 返回首页
Set.prototype.has() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

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: true console.log(set1.has(5)); // Expected output: true console.log(set1.has(6)); // Expected output: false

구문

js
has(value)

매개변수

value

Set 객체에서 존재 여부를 판별할 값.

반환 값

Set 객체에 값이 존재하면 true, 아니면 false.

예제

has() 메서드 사용하기

js
const mySet = new Set(); mySet.add("foo"); console.log(mySet.has("foo")); // true console.log(mySet.has("bar")); // false const set1 = new Set(); const obj1 = { key1: 1 }; set1.add(obj1); console.log(set1.has(obj1)); // true console.log(set1.has({ key1: 1 })); // false, 형태만 같은 서로 다른 객체의 참조이기 때문 console.log(set1.add({ key1: 1 })); // set1의 요소가 2개로 늘어남

명세서

Specification
ECMAScript® 2027 Language Specification
# sec-set.prototype.has

브라우저 호환성

Enable JavaScript to view this browser compatibility table.

같이 보기