배열의 요소들을 더해 계산한 후 결과값을 실행한다.

const array = [1, 2, 3, 4, 5]
const reducer = (prevValue, currValue) => prevValue + currValue;

//1, 2, 3, 4, 5
console.log(array.reduce(reducer));
//결과 15

Last modified: 2022년 01월 18일

Comments

Write a Reply or Comment

Your email address will not be published.