[JS] Set

JongHoon Son·2022년 6월 30일
0

JS

목록 보기
7/9
post-thumbnail

생성

const mySet = new Set();

Array to Set

const mySet = new Set(Array);

Set to Array

const myArr = Array.from(mySet);

요소 추가

mySet.add(value)

요소 삭제

mySet.delete(value);

요소 모두 삭제

mySet.clear();

특정 요소 존재 여부 확인

mySet.has(value);

요소 1개 출력

mySet.get(key);

전체 요소 출력

for (let item of mySet) {
	console.log(item);
}

전체 요소 갯수 출력

mySet.size

profile
FE 공부

0개의 댓글