I want to calculate sum with forEach array function in JavaScript. But I don't get what I want.
function sum(...args) {
args.forEach(arg => {
var total = 0;
total += arg;
console.log(total);
});
}
sum(1, 3);
How to get total with forEach, or use reduce method?