37장 Set과 Map
37.1 Set
구분
배열
Set 객체
37.1.1 Set 객체의 생성
// 인수 x
const set = new Set()
console.log(set) // Set(0){}
// 인수 o
const set = new Set([1, 2, 3, 3])
console.log(set) // Set(3){1, 2, 3} > 중복 요소인 3은제거됨
const set2 = new Set("hello")
console.log(set2) // Set(4){"h", "e", "l", "o"} > 중복 요소인 l은 제거됨
// 중복을 허용하지 않는 특성을 활용해 배열에서 중복된 요소를 제거할 수 있다.
// 배열의 중복 요소 제거
const uniq = array => array.filter((v, i, self) => self.indexOf(v) === i)
console.log(uniq([2, 1, 2, 4, 3, 4])) // [2, 1, 3, 4]
// Set의 중복 요소 제거
const uniq2 = array => [...new Set(array)]
console.log(uniq([2, 1, 2, 4, 3, 4])) // [2, 1, 3, 4]37.1.2 요소 개수 확인
37.1.3 요소 추가
34.1.4 요소 존재 여부 확인
34.1.5 요소 삭제
37.1.6 요소 일괄 삭제
37.1.7 요소 순회
27.1.8 집합 연산
37.2 Map
구분
객체
Map 객체
37.2.1 Map 객체의 생성
37.2.2 요소 개수 확인
37.2.3 요소 추가
37.2.4 요소 취득
37.2.5 요소 존재 여부 확인
37.2.6 요소 삭제
37.2.7 요소 일괄 삭제
37.2.8 요소 순회
Map 메서드
설명
Last updated