-
map(), filter(), reduce() 에 대하여개념정리 2021. 1. 12. 01:02
map()이란?
배열의 요소 각각에 주어진 함수를 실행한 결과를 모아서 새로운 배열을 리턴합니다.
const arr = [1, 4, 9, 16];
const map = arr.map(el => el + 1);
console.log(map); // [2, 5, 10, 17]
filter()이란?
주어진 함수의 조건을 통과하는 요소를 모아 새로운 배열을 리턴합니다.
const arr = [1, 4, 9, 16];
const filter = arr.filter(el => el > 8);
console.log(filter); // [9, 16]
reduce()이란?
배열의 요소에 주어진 리듀서(reducer) 함수를 실행하고, 하나의 결과값을 리턴합니다.
const arr = [1, 4, 9, 16];
const reduce = arr.reduce( (acc, cur) => acc + cur, 초기값);
console.log(reduce); // 30
'개념정리' 카테고리의 다른 글
Data structure (stack, queue) (0) 2021.01.19 Prototype과 JavaScript에서 Object를 생성하는 방법 (0) 2021.01.14 Object Oriented Programming (0) 2021.01.14 this 와 call, apply, bind 키워드 (0) 2021.01.14 for...in, for...of 의 차이 그리고 foreach (0) 2021.01.10