我试图用每个数组中最大的元素返回 arr
,但是我收到一条错误消息。谢谢。
function largestOfFour(arr) {
for (var i = 0; i<arr.length; i++) {
return Math.max.apply(Math, arr[i]);
}
}
largestOfFour([1,2,4],[23,22,0])
TypeError: second argument to Function.prototype.apply must be an array
最佳答案
使用 map
函数
array.map(function(array) {
return Math.max.apply(Math, array)
})
关于javascript - 在数组的数组中查找最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32614313/