-3

I'm trying to get the length of a multidimensional Array as follows, but when I test it with alert() I get undefined. I would like to know how many items has the parent array (myArray), as I would like then to use it in a cycle i=0;i<myArray.length;i++.

Any ideas?

myArray = array = {
        'def':array = {
            "first":"value",
        },
        0 : array = {
            "T":"Some text",
        },
        1 : array = {
            "T":"Some text",
        },
};

leng = myArray.length;
alert(leng);
4

1 回答 1

3

您可以使用数组语法创建数组:

    array = ["first item", {second:'item'}, 3];
    array.def = {something:"else"};
    alert(array.length);

以下是使用数组数组创建多维数组的方法:

    array = [
        [1,2,3],
        [4,5,6],
        [7,8,9]
    ];

    alert(array[0][2]); // alerts "3"
于 2012-11-09T15:12:28.300 回答