Array.prototype.forEachbeginnerlet total = 0
[10, 20, 30].forEach(n => { total += n })
total // β 60Use forEach() to iterate over elements and accumulate a value in an outer variable.
Array.prototype.forEach(callback) executes a provided function once for each array element, in order. Unlike map or filter, it always returns undefined and is used exclusively for side effects.
Challenge: Implement sumArray(nums) that uses forEach to sum all numbers by accumulating into an external variable.
sumArray([1, 2, 3, 4]) // β 10
sumArray([]) // β 0