JavaScript finding the largest integer in an array of arrays

后端 未结 5 424
独厮守ぢ
独厮守ぢ 2021-01-23 21:30
function largestOfFour(arr) {
    var newArray = [];
    for(var i =0; i <=arr.length-1; i++){
        console.log(arr[i]);
        newArray[i] = Math.max(arr[i]);
           


        
5条回答
  •  孤独总比滥情好
    2021-01-23 22:13

    Edited: In order to add values to the array, I'd suggest using the push methodn. As in: NewArray.push(Math.max(...sub[i])); or newarray.push(math.max.apply(null, sub[i]). An alternative is alocating, when declarating the array, the size it will take: Var newArray = new Array(arr.length); There's this new spread operator (...) in javascript !

提交回复
热议问题