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

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

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