方法一、遍历数组 var tmp = new Array(1,12,4,124.45,8,99998,456); var max = tmp[0]; for(var i=1;i<tmp.length;i++){ if(max<tmp)max=tmp;}
Math.Max.Apply(Math,tmp); 也可以写成 Math.Max.Apply({},tmp);的简写形式
总: 两个方法都可以作为对象方法扩展存在,例如 Array.prototype.max=function(){ 方法体 } //prototype可以像对象添加属性或方法 调用的时候就成了 var tmp = new Array(1,12,4,124.45,8,99998,456); tmp.max();//99998
|