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 July 2015.
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® 2025 Language Specification # sec-set.prototype.add |
브라우저 호환성
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
add |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.