📜  javascript代码示例中的函数数组总和

📅  最后修改于: 2022-03-11 15:04:10.698000             🧑  作者: Mango

代码示例3
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