**Tell us what’s happening:**

I’m having trouble debugging my code.

Right now I want to iterate through each sub array (x) and every item (i) in each subarray. After I’m done iterating through every “i” for a given value of “x”, I assign the largest number to max[x]. I was able to return the largest item in a single array with a single for loop, but adding in the second loop to iterate through items in a subarray is giving me problems.

I asked the function to return an array consisting of x, i and max, but I’m getting an error saying that i is undefined. I can’t for the life of me figure out why! Can anyone help me understand?

**Your code so far**

```
function largestOfFour(arr){
let max = [0];
for (let x=0; x<arr.length-1; x++){
for (let i = 0; i < arr[x].length-1; i++){
if (arr[x][i]>max[x]){
max[x] = arr[x][i];
}
}
}
let a = [x,i,max];
return a;
}
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_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36`

.

**Link to the challenge:**

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