找出数组
[
[3,4,5],
[1,2,5,9],
[3,0,7],
[3,4,1]
]
中每个数组的最大值,组成一个新数组:
可以利用
函数 Maht.max()
function fnArr(arr){
var temp_arr=[];
arr.forEach((item,index)=>{
temp_arr.push(Math.max(...item))
})
return temp_arr
}
console.log(
fnArr([
[3,4,5],
[1,2,5,9],
[3,0,7],
[3,4,1]
])
)
浏览器打印: