일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- windowwidth
- classList remove
- 리엑트할수있는퍼블리셔라규
- react-router
- className
- classList toggle
- 접근성
- 대표님물리기없기
- 내배위의고양이
- resize
- react-router-dom
- 방심은금물
- 2020
- 포트폴리오
- 언젠간가겠지
- chart.js
- 를
- 클래스 토글
- ROUTER 버전6
- react
- classList
- 퍼블리싱
- 안짤렸다
- 냥빨이다가온다
- classList add
- chart responsive
- 커스텀훅
- 간식금지다!
Archives
- Today
- Total
틈
[ES6] new Set() 본문
new Set()
- array 에서 중복 제거할 때 사용
사용방법
const arr = [1,2,3,4,5,6,1,2];
const set = new Set(arr);
console.log(set); // {1,2,3,4,5,6}
console.log([...set]) // [1,2,3,4,5,6]
중복을 해결하고 싶은 arr 변수를 인자를 넣고 출력하면
위와 같이 set 형태가 출력되는데,
이를 전개연산자를 이용해 다시 출력하면, 중복이 제거된 객체를 얻을 수 있다.
- new Set(객체).add(1) : 객체에 1 추가
- new Set(객체).delete(1) : 객체에 1 삭제
- new Set(객체).has(1) : 객체에 1이 있는지 없는지 체크
- new Set(객체).size() : length 와 동일
'code > Javascript' 카테고리의 다른 글
fragment(createDocumentFragment) (0) | 2023.05.26 |
---|---|
classList (0) | 2023.05.22 |
try catch 구문 (0) | 2023.01.26 |
select 에서 선택된 값 가져오기 (0) | 2023.01.20 |
[jQuery] count up (0) | 2022.12.01 |
Comments