1var numbers = [3, 5, 7, 2];
2var sum = numbers.reduce((x, y) => x + y);
3console.log(sum); // returns 17
4
5// other way
6
7x = sumAll(1, 123, 500, 115, 44, 88);
8
9function sumAll() {
10 var i;
11 var sum = 0;
12 for (i = 0; i < arguments.length; i++) {
13 sum += arguments[i];
14 }
15 return sum;
16}
1// define a list
2const list = [1,2,3,4,5];
3
4// create a function return result of sum of elements
5const result = () => {
6 let sum = 0;
7 for (let i = 0; i < list.length; i++) {
8 sum += list[i];
9 }
10 return sum
11}
12console.log(result());