Reduce function

 let a = [12,3,4,5,5];


let number = a.reduce(function(accumulator,currentNuber){

  return accumulator+currentNuber;

})

console.log(number);


The reduce() method reduces the array to a single value.

The reduce() method executes a provided function for each value of the array (from left-to-right).

The return value of the function is stored in an accumulator (result/total).

Note: reduce() does not execute the function for array elements without values.

Note: This method does not change the original array

Comments