A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Set/Set below:

Set() 생성자 - JavaScript | MDN

Set() 생성자

Baseline Widely available

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
구문
new Set()
new Set(iterable)

참고: Set()은 오직 new와 함께 생성할 수 있습니다. new 없이 생성을 시도하면 TypeError가 발생합니다.

매개변수
iterable Optional

순회 가능한 객체가 전달되면 모든 요소가 새로운 Set에 추가됩니다.

이 매개변수를 지정하지 않거나 값이 null일 경우 새로운 Set은 비어있게 됩니다.

반환 값

새로운 Set 객체.

예제 Set 객체 사용하기
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);
명세서 브라우저 호환성 같이 보기

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4