[JavaScript] Set
Set중복되지 않는 유일한 값들의 집합요소에 순서가 없다.인덱스로 요소에 접근할 수 없다.Set 객체 생성const set1 = new Set();console.log(set); // Set(0) {}const set2 = new Set([1, 2, 3, 3]);console.log(set); // Set(3) {1, 2, 3}const set3 = new Set('hello');console.log(set); // Set(4) {"h", "e", "l", "o"}//중복 제거const uniq = array => array.filter((v, i, self) => self.indexOf(v) === i);const uniq = array => [ ... new Set(array)];// 두 코드 실행 ..
2023. 2. 16.
[JavaScript] 이터러블
이터러블스프레드 문법하나로 뭉쳐 있는 여러 값들의 집합을 전개하여 개별적인 값들의 목록으로 만드는 것// ... [1, 2, 3]은 [1, 2, 3]을 개별 요소로 분리한다.(-> 1, 2, 3)console.log(...[1, 2, 3]); // 1 2 3consolg.log(...'Hello'); // H e l l o배열 디스트럭처링 할당(구조 분해 할당)구조화된 배열과 같은 이터러블 또는 객체를 destructuring 하여 1개 이상의 변수에 개별적으로 할당하는것const arr = [1, 2, 3];//1, 2, 3을 각각 one, two, three에 개별적으로 할당const [one, two, three] = arr;console.log(one, two, three); // 1 2 3이터레..
2023. 2. 16.