思路:
总共使用三种方法
1. for 循环 遍历数组的下标
2.利用Math 取最大值
3.利用 Math.max.apply(null,arr)
let arr = [34, 78, 20, 99, 0, 2] //如何求最大值
let max = arr[0] //设置一个默认项
for (let index = 0; index < arr.length; index++) {
if (arr[index] > max) {
max = arr[index]
}
}
// console.log("数组最大值", max)
//方法二
// console.log(Math.max(...arr))
//方法三
console.log(Math.max.apply(null, arr))