Question

I initialize an array as such:

    imgArray = [];
    imgArray[0,0] = "image1";
    imgArray[1,0] = "image2";
    imgArray[0,1] = "image3";
    imgArray[1,1] = "image4";
    imgArray[0,2] = "image5";
    imgArray[1,2] = "image6";

When I do an alert for imgArray[0,2], I get image6. When I do an alert for imgArray[0,1], I get image4. When I do an alert for imgArray[1,1], I get image4 which is correct.

It appears that the imgArray is totally ignoring my 0 dimension.

Was it helpful?

Solution

Multidimensional Arrays in Javascript are written in seperate brackets:

imgArray = [];
imgArray[0] = [];
imgArray[1] = [];
imgArray[0][0] = "image1";
imgArray[1][0] = "image2";
imgArray[0][1] = "image3";
imgArray[1][1] = "image4";
imgArray[0][2] = "image5";
imgArray[1][2] = "image6";

OTHER TIPS

imgArray = [];
imgArray[0] = ["image1", "image2"];

Multidimensional arrays in JavaScript are simply nested arrays.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top