# 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] )

``````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 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`.

https://www.freecodecamp.org/challenges/return-largest-numbers-in-arrays

0 Likes

#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
``````
1 Like

#3

Ah ok, thank you for explanation!

0 Likes