Movatterモバイル変換


[0]ホーム

URL:


  1. 개발자를 위한 웹 기술
  2. JavaScript
  3. JavaScript 참고서
  4. 표준 내장 객체
  5. Set
  6. Set.prototype.has()

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

View in EnglishAlways 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 객체에 주어진 요소가 존재하는지 여부를 판별해 반환합니다.

시도해 보기

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)

매개변수

value

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

반환 값

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

브라우저 호환성

같이 보기

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2026 Movatter.jp