📜  在javascript代码示例中按函数从数组中查找最大数

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

代码示例2
function largestElements(numbers) {
    var largest = 0;
    for (let i = 0; i < numbers.length; i++) {
        var elements = numbers[i];
        if (elements > largest) {
            largest = elements;
        }
    }
    return largest;
}
const numbers = [2, 3, 4, 8, 5, 2, 4];
console.log(largestElements(numbers));
//Output: 8