The reduce()
array prototype method uses a user supplied accumulator to calculate all element values into a single value.
The call back function will most commonly take in arguments of accumulator, currentValue
, where the accumulator
is the
user supplied value and the currentValue
is the value of the array index position that is currently being iterated through.
The call back function can also take in index
and array
where index is the index position of the array currently being
iterated through and array is the value of the full array.
The final syntax will look something like this most of the time:
array.reduce((accumulator, variable) => {