Why it is undefined?

Why it is undefined?
0

#1

Tell us what’s happening:
I have hard times to understand why inner[outer] is undefined when i am in second for loop. All it returns is array of four 0 ( [0,0,0,0] )

Your code so far

function largestOfFour(arr) {
    var newArray = [];
    var tempNumber = 0;

    for (var outer = 0; outer < arr.length; outer++) {
        for (var inner = 0; inner[outer] < inner.length; inner++) {
            if (inner[outer] > tempNumber) {
                tempNumber = inner[outer];
            }
        }
        newArray.push(tempNumber);
    }
    return console.log(newArray);
}

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

Your browser information:

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

Link to the challenge:


#2

You declared a
var outer to the value 0 and declared
var inner to the value of 0
and then you did inner[outer]
which mean you did something like that

0[0] // -> and this will return undefined cuz 0 is an integer and not array

#3

Ah ok, thank you for explanation!