[JavaScript] 모던 자바스크립트 Deep Dive 37장 - Set과 Map
1. Set Set 객체는 중복되지 않는 유일한 값들의 집합이다. Set 객체는 배열과 유사하지만 다음과 같은 차이가 있다. 동일한 값을 포함할 수 없다. 요소 순서에 의미가 없다. 인덱스로 요소에 접근할 수 없다. 1-1 Set 객체의 생성 Set 생성자 함수로 생성 const set = new Set(); console.log(set); // Set(0) {} 배열에서 중복된 요소 제거 const uniq = array => array.filter((v, i, self) => self.indexOf(v) === i); console.log(uniq([2, 1, 2, 3, 4, 3, 4])); // [ 2, 1, 3, 4 ] // Set 이용 const uniq2 = array => [...new Se..
2023.02.08