1.直接遍历数组
var arr = [1,12,4,124,45,8,99998,456]; var max = arr[0]; for(var i=1;i<arr.length;i++){ if(max<arr[i]) max=arr[i]; }
2.借用Math的方法
var arr = [1,12,4,124,45,8,99998,456]; var max = Math.max.apply(Math,arr);
取最小值反之;
3.数组平均值
var arr = [5,8,2,3,7,6,9,1,4,8,3,0];
var sum=0;
for(var i = 0; i < arr.length; i++){
sum += arr[i];
}
var mean = sum / arr.length;
console.log(mean);