从数组中找到最大数

var a = [2,3,4,5],

c = Math.max.apply(null,a);



console.log(c);

console.log(Math.max.apply(null,[3,8,44,48]));

console.log(Math.max.call(null,3,8,44,48));

 

当数组中不是只有数字时找到最大的那个数字

var nums = "adc123efg789hh6",

		ary = [];

		nums.replace(/\d{1,3}/g,function(num){ //d为正则查找数字,找出nums里所有数字

				ary.push(num);


		});



		console.log(Math.max.apply(null,ary));

 

posted @ 2015-03-14 15:14  唸随爱  阅读(169)  评论(0编辑  收藏  举报