# Return the largest number in array

hello

i want to return the largest numbers in array but i dont understand the end of the solution:

tt[n] = largestnumber

how can tt cal “a” if “a” didn’t run inside it?

if tt[a] is now assigned to largestnumber why it doesn’t change largestnumber properties?

``````var arr = [[1,2],[6,7]];
var tt = [];
for (a=0; a<arr.length; a++){

var largestnumber = arr[a];
for (var b=1; b<arr[a].length; b++){
if (arr[a][b]> largestnumber){
largestnumber = arr[a][b];
}
}
tt[a] = largestnumber;     // the part i don't understand
}
console.log(tt);
``````

If you are asking how can tt call “a”, then the answer, is it can not. tt[a] references a specify element (sub array in this case) of tt depending on the value a is in the for loop iteration.

If a = 0 (first iteration of outer for loop), then tt[a] is tt, which then gets assigned the current value of largestnumber (in this case the value 2 gets assigned to tt).

If a = 1 (2nd iteration of outer for loop), then tt[a] is tt, which then gets assigned the current value of largestnumber (in this case the value 7gets assigned to tt).

2 Likes

got it. so as long we are inside the loop whatever a is reflects the tt array although a is outside the loop

i could also do insted of

`````` tt[a] = largestnumber;
``````

that

``````tt.push(largestnumber);

``````