Answers for "reduce() method executes a reducer function on each element of the array and returns a single output value."

0

reduce() method executes a reducer function on each element of the array and returns a single output value.

const numbers = [1, 2, 3, 4, 5, 6];

function sum_reducer(accumulator, currentValue) {
  return accumulator + currentValue;
}

let sum = numbers.reduce(sum_reducer);
console.log(sum); // 21

// using arrow function
let summation = numbers.reduce(
  (accumulator, currentValue) => accumulator + currentValue
);
console.log(summation); // 21
Posted by: Guest on April-14-2022

Code answers related to "reduce() method executes a reducer function on each element of the array and returns a single output value."

Browse Popular Code Answers by Language