배열 평탄화하기 : Array.prototype.flatMap()과 Map.prototype.entries()

Array.prototype.flatMap()

let arr1 = [1, 2, 3, 4];

arr1.map(x => [x * 2]);
// [[2], [4], [6], [8]]

arr1.flatMap(x => [x * 2]);
// [2, 4, 6, 8]

// 한 레벨만 평탄화됨
arr1.flatMap(x => [[x * 2]]);
// [[2], [4], [6], [8]]

Map.prototype.entries()

기존의 일반 객체는 Object.entries()를 사용했다면. map객체는 내장메서드인 entries()를 사용하면 된다.

## Reference
- https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap
- 

좋은 웹페이지 즐겨찾기