数组中的最大值和最小值
var arr = [12, 56, 25, 5, 82, 51, 22]; var max = arr[0]; var min = arr[0]; for (var i = 1; i < arr.length; i++) { if (arr[i] > max) { max = arr[i]; } if (arr[i] < min) { min = arr[i]; } } console.log("最大值是:" + max); console.log("最小值是:" + min);