filmov
tv
JS Tip: Sum an array with reduce()
Показать описание
The reduce() method executes a user-supplied "reducer" callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value.
Perhaps the easiest-to-understand case for reduce() is to return the sum of all the elements in an array.
Perhaps the easiest-to-understand case for reduce() is to return the sum of all the elements in an array.