有没有找到含有未定义值的稀疏数组的最大值的正确方法?在一个稀疏的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