Set.prototype.add()
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 ì¸ì¤í´ì¤ì add() ë©ìëë ê°ì ê°ì¸ ììê° ì´ Setì ìë¤ë©´ ì§ì ë ê°ê³¼ í¨ê» ìë¡ì´ ìì를 ì´ Setì ì½ì
í©ëë¤.
ìëí´ ë³´ê¸°
const set1 = new Set();
set1.add(42);
set1.add(42);
set1.add(13);
for (const item of set1) {
console.log(item);
// Expected output: 42
// Expected output: 13
}
구문
js
add(value)
매ê°ë³ì
value-
Setê°ì²´ì ì¶ê°í ììì ê°.
ë°í ê°
ì¶ê°ë ê°ì´ í¬í¨ë Set ê°ì²´.
ìì
>add ë©ìë ì¬ì©í기
js
const mySet = new Set();
mySet.add(1);
mySet.add(5).add("some text"); // ê³ì ë¶ì¼ ì ìì
console.log(mySet);
// Set [1, 5, "some text"]
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-set.prototype.add> |