How to add all numbers in an array in JavaScript?

To add all numbers in an array in JavaScript, do this: array.reduce((a, b) => a + b, 0).

Here's how you do it:

const array = [ 1, 2, 3 ];
const sum = array.reduce((a, b) => a + b, 0);

console.log(sum); // 6