Q: JavaScript TypeError when indexing into 2D array I am working on some code that manipulates a 2D array of "cell" objects. 
function randomDestFromStart(cell, temp)
{
    function addPossible(x, y)
    {
        var test1 = temp[x];
        var test2 = test1[y];  // This line
        // ... //
    }

    for (var i = 0; i < temp[0].length; i++)
        addPossible(cell.x, i);

    // ... //
}

temp is the 2d array, and cell is a particular Cell object. Defining test2 results in the following error:
TypeError: test1 is undefined

I have confirmed in the debugger that x and y are valid integers (in this particular case they are 0 and 1 respectively). temp is a valid array consisting of 5 subarrays of Cell objects, so there shouldn't be any sort of index out of bounds error. There doesn't seem to be an issue indexing one level into temp seeing as test1 is a valid array of 5 cells (essentially a row of temp). The problem is when I index into the 2nd dimension of the array, which is strange since indexing into the same exact array works in other parts of the code.
EDIT: The problem seems to be with the inputs for x and y. When I hardcode these values everything works fine. For example, addPossible(2, 3) works. The error occurs when the values are provided dynamically, but this is strange because the debugger shows x and y as completely normal and valid integers even in these cases. I am 99% sure this is NOT an out of bounds issue. I have checked and the array is 5x5, and x and y are always between 0 and 4.

A: Most likely your temp array is larger than whatever value exists in cell.x. Its also possible that cell.x is one too big and you want cell.x -1
