JavaScript 배열 reduce()

(자바스크립트 배열 reduce()에서 넘어옴)

1 개요[ | ]

JavaScript Array.reduce()
자바스크립트 배열 reduce()
const numbers = [100, 20, 10];
const result = numbers.reduce(function(total, num) {
  return total + num;
});
console.log( result ); // 130 = 100 + 20 + 10
const numbers = [100, 20, 10];
const reducer = (accumulator, currentValue) => accumulator + currentValue;
console.log(numbers.reduce(reducer));    // 130 = 100 + 20 + 10
console.log(numbers.reduce(reducer, 5)); // 135 = 5 + 100 + 20 + 10
const numbers = [100, 20, 10];
const result = numbers.reduce(function(total, num) {
  return total - num;
});
console.log( result ); // 70 = 100 - 20 - 10

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}