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 |
๋ธ๋ผ์ฐ์ ํธํ์ฑ
Loadingโฆ