Javascript多维数组返回错误的维度



我这样初始化一个数组:

    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";

当我对imgArray[0,2]执行警告时,我得到image6。当我对imgArray[0,1]执行警告时,我得到image4。当我对imgArray[1,1]做一个警告时,我得到image4这是正确的

imgArray似乎完全忽略了我的0维

Javascript中的多维数组用单独的括号表示:

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";
imgArray = [];
imgArray[0] = ["image1", "image2"];

JavaScript中的多维数组是简单的嵌套数组。

相关内容

  • 没有找到相关文章