how to add all the numbers in an array in javascript code example
Example 1: javascript sum of array
const sum = arr => arr.reduce((a, b) => a + b, 0);
Example 2: sum of an array
const sum = (...args) => args.reduce((a, b) => a + b, 0);
console.log(sum(1,2,3)); // returns 6