Variables: Return Largest Numbers in Arrays

How come the console cannot identify var newArray = [] ?

Your code so far


function largestOfFour(arr) {
  // You can do this!
  var newArray = [];
  for(var i = 0; i < arr.length; i++){
    var maxNum = arr[i][0];
    for(var j = 1; j < arr[i].length; j++){
      if(arr[i][j] > maxNum){
        maxNum = arr[i][j];
      }
    } newArray[i] = maxNum;
  }
  return newArray;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
console.log(newArray);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.80 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-algorithm-scripting/return-largest-numbers-in-arrays/

Solution works. The newArray doesn’t show probably because it is not logged or console.log. You need to call it

newArray is a local variable, you need or add the console.log inside the function right before the return statement
or wrap the function call in the console.log