Set() ìì±ì
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() ìì±ìë 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
new Set()
new Set(iterable)
매ê°ë³ì
iterableOptional-
ìí ê°ë¥í ê°ì²´ê° ì ë¬ëë©´ 모ë ììê° ìë¡ì´
Setì ì¶ê°ë©ëë¤.ì´ ë§¤ê°ë³ì를 ì§ì íì§ ìê±°ë ê°ì´
nullì¼ ê²½ì° ìë¡ì´Setì ë¹ì´ìê² ë©ëë¤.
ë°í ê°
ìë¡ì´ Set ê°ì²´.
ìì
>Set ê°ì²´ ì¬ì©í기
js
const mySet = new Set();
mySet.add(1); // Set [ 1 ]
mySet.add(5); // Set [ 1, 5 ]
mySet.add(5); // Set [ 1, 5 ]
mySet.add("some text"); // Set [ 1, 5, 'some text' ]
const o = { a: 1, b: 2 };
mySet.add(o);
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2027 Language Specification > # sec-set-constructor > |