# Question of Return Largest Numbers in Arrays

Tell us what’s happening:
Dear all,
I’m wondering why the following code won’t work. Instead, the code next will work.

1. Why can’t I put
` let largestNum = arr[i][0];`
after
`for (let j=0; j<arr[i].length; j++){`

2. Where should I put `return ans;`. It seems like it matters that `return ans;` should only be added before certain curly bracket, but I’m often confused after which one.
Thanks for helping

``````
function largestOfFour(arr) {
let ans =[];
for(let i= 0; i< arr.length; i++){
for (let j=0; j<arr[i].length; j++){
let largestNum = arr[i][0];
if (arr[i][j]> largestNum){
largestNum= arr[i][j];
}
} ans[i] = largestNum
}
return ans;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
``````
``````function largestOfFour(arr) {
let ans =[];
for(let i= 0; i< arr.length; i++){
let largestNum = arr[i][0];
for (let j=0; j<arr[i].length; j++){
if (arr[i][j]> largestNum){
largestNum= arr[i][j];
}
} ans[i] = largestNum
}
return ans;
}

largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);
``````
``````  **Your browser information:**
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.0 Safari/605.1.15`

Challenge: Return Largest Numbers in Arrays

We wanna declare a `largestNum` variable before we start testing the respective array numbers. We use its first element as an initial value, then we compare it with every other element. If another element is larger, its assigned as the value of `largestNum` and any consecutive elements are being compared towards it. Keep in mind all that can be achieved in different variations and slightly more efficient. If you were to declare `let largestNum = arr[i][0]` on every iteration(for every element we test in the array), we will always compare the current element with the first element in the array and not with the largest element so far, so in the end, what we will get as a result(if we take in mind the remaining logic of your code), will be the largest number between the first element and the last element in the array, as we initiate a new value for the largest element on every loop.