有沒有找到含有未定義值的稀疏數組的最大值的正確方法?在一個稀疏的javascript數組中尋找最大值
感謝
var testArr=[undefined,undefined,undefined,3,4,5,6,7];
console.log('max value with undefined is ',(Math.max.apply(null,testArr)));
// max value with undefined is NaN
console.log('max with arr.max()',testArr.max());
// Error: testArr.max is not a function
testArr=[null,null,null,3,4,5,6,7];
console.log('max value with null is ',(Math.max.apply(null,testArr)));
// max value with null is 7
我不想做的forEach如果有一個內置的方法。
的forEach是一個內置的方法的 – 2015-01-20 21:55:09
可能重複的[JavaScript的:最大和最小數組值](http://stackoverflow.com/questions/1669190/javascript-min- max-array-values) – JAL 2015-01-20 21:55:12
@DanielWeiner內置方法*查找最大值* – glyph 2015-01-20 22:00:33