The
reduce()
method calculates the sum of the array of numbers by executing the “reducer” callback function on each element of the array. The
accumulator
argument is the value of the previous call of the function. Its initial value is
0
; the
currentValue
is the value of the array element. For each call of the function, the value of the previous function call is added to the value of the array element. The return value of the
reduce()
method is the final value of the “reducer” callback function after it’s been executed on each element of the array. In this case, it calculates the sum of the array numbers.