Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Array sum by function in javascript

function sumNumbers(numbers) {
    var sum = 0;
    for (let i = 0; i < numbers.length; i++) {
        var elements = numbers[i];
        sum = sum + elements;
    }
    return sum;
}
const numbers = [2, 3, 4, 5, 2, 4];
console.log(sumNumbers(numbers));
//Output: 20
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Array #sum #function #javascript
ADD COMMENT
Topic
Name
9+5 =