微语 微语:代码适合中午敲,早晚出BUG

求数组中最大值 JavaScript

方法一:

arr = [1, 3, 5, 79, 11];
            let max = arr[0];
            arr.forEach(function(v, i) {
                if (v > max) {
                    max = v;
                }
            })
console.log("最大值:", max)

方法二:

arr = [1, 3, 5, 79, 11]
            let max = arr[0];
            for (let i = 0; i < arr.length; i++) {
                if (arr[i] > max) {
                    max = arr[i]
                }
            }
            console.log("最大值", max)