Array.prototype.reducebeginnerconst nums = [1, 2, 3, 4]
nums.reduce((acc, n) => acc + n, 0) // β 10Use reduce() with an initial accumulator of 0 to compute the sum of all elements.
reduce() executes a reducer function on each element, accumulating a single result.
[1, 2, 3].reduce((acc, n) => acc + n, 0) // 6
The second argument (0) is the initial value of the accumulator.