可能重複:
How to use Math.max, etc. as higher-order functions爲什麼我不能在Javascript中編寫[1,2,3] .reduce(Math.max)?
使用Mozilla的JavaScript 1.6數組 '擴展' 功能(地圖,減少,過濾器等),那爲什麼下面將按預期:
var max = [1,2,3].reduce(function(a,b) { return Math.max(a,b); });
但以下不起作用(它產生NaN):
var max2 = [1,2,3].reduce(Math.max);
是否因爲Math.max是一個可變參數函數?
不完全的話題,但如果你想輕鬆地減少陣列到最大值,您可以用'。適用()''上Math.max'。 'var max = Math.max.apply(null,[1,2,3,4]);' – user113716