1var total = numbers.reduce(function(total, current) {
2 return total + current;
3}, 0);
4
5console.log(total);
1///sum of odd numbers in an array javascript without loop
2var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
3
4var evenNumbers = numbers.filter(function(item) {
5 return (item % 2 == 0);
6});
7
8console.log(evenNumbers);
1var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
2
3var evenNumbers = numbers.filter(function(item) {
4 return (item % 2 == 0);
5});
6
7console.log(evenNumbers);