javascript取得多數組中最大值和最小值的方法
apply();可由多個數組中抓出最大值與最小值,範例如下:
var a =[10 , 20 , 30 , 40 ]; var $maxheight=Math . max . apply ( null , a ); var $minheight=Math . min . apply ( null , a ); //最小值 document.write($maxheight); //輸出最大值 40 document.write($minheight); //輸出最小值 10
教學撰寫:徐嘉裕 Neil hsu