배열 평탄화하기 : 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
-
Author And Source
이 문제에 관하여(배열 평탄화하기 : Array.prototype.flatMap()과 Map.prototype.entries()), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@gygy/배열-평탄화하기-Array.prototype.flatMap과-Map.prototype.entries저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)