1、循环遍历数组元素
//最小值
var array = [5, 7, 2, 3, 4, 1, 7, 9, 6];
var index = 0,min = array[index]
for(var i=0; i<array.length; i++){
if(min>array[i]){
min = array[i]
index = i
}
}
console.log(min)
//最大值
var array = [5, 7, 2, 3, 4, 1, 7, 9, 6];
var index = 0,max= array[index]
for(var i=0; i<array.length; i++){
if(max<array[i]){
max= array[i]
index = i
}
}
console.log(max)
2、apply
var array = [5, 7, 2, 3, 4, 1, 7, 9, 6];
//最小值
min = Math.min.apply(null,array)
console.log(min)
//最大值
max = Math.max.apply(null,array)
console.log(max)
3、展开运算符
var array = [5, 7, 2, 3, 4, 1, 7, 9, 6];
//最小值
min = Math.min(...array)
console.log(min)
//最大值
max = Math.max(...array)
console.log(max)