Using the forEach function defined for an array, find the sum of the array of numbers. [function add_all(arr) {...}] code example
Example 1: sum javascript
console.log(
[1, 2, 3, 4].reduce((a, b) => a + b, 0)
)
console.log(
[].reduce((a, b) => a + b, 0)
)
Example 2: sum all elements in array javascript
arr.reduce((a, b) => a + b)