对于一个数组,怎样才能最快找出数组中的最大值
var nums = [1,56,78,345,67,89,3423,34,5,7]; var max = 0; for(var i=0; i<nums.length; i++){ if(nums[i] > max){ max = nums[i]; } } console.log( "第一种排序方式:", max ); console.log('第二种排序方式:',Math.max(1,56,86,2,36,53,45,143,56,89)); nums.sort(function(a, b){return a-b}); console.log("第三种排序方式:", nums[0]);