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 ๊ฐ์ฒด์— ์ฃผ์–ด์ง„ ์š”์†Œ๊ฐ€ ์กด์žฌํ•˜๋Š”์ง€ ์—ฌ๋ถ€๋ฅผ ํŒ๋ณ„ํ•ด ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.

์‹œ๋„ํ•ด ๋ณด๊ธฐ

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ยฎ 2026 Language Specification
# sec-set.prototype.has

๋ธŒ๋ผ์šฐ์ € ํ˜ธํ™˜์„ฑ

๊ฐ™์ด ๋ณด๊ธฐ