1. ## Multidimensional Array Length

Hi.

Is there any function or property for finding out the size of the first (or for that matter any) dimension of a multidimensional array?

EDIT:

There seems to be no such functionality, I found a solution that does not require it. If anyone is reading this for the same reason; it needs to be scripted.

2. If I understand

Code JavaScript:
```<script type="text/javascript">

var A = [

["The Time Through Ages","In the Name of Allah, Most Gracious, Most Merciful,","1. By the Time,","2. Verily Man is in loss,"," 3. Except such as have Faith, and do righteous deeds, and (join together) in the mutual enjoining of Truth, and of Patience and Constancy."],

["The Opening", "1. In the name of Allah, Most Gracious, Most Merciful.", "2. Praise be to Allah, the Cherisher and Sustainer of the worlds;", "3. Most Gracious, Most Merciful;", "4. Master of the Day of Judgment.", "5. Thee do we worship, and Thine aid we seek.", "6. Show us the straight way,", "7. The way of those on whom Thou hast bestowed Thy Grace, those whose (portion) is not wrath, and who go not astray."]

]

alert (A[0][0]);        // The Time Through Ages

var s = "";
var t = "<table border=2 ><tbody>";

for(var i=0; i< A.length; i++) {

t +="<tr><td>" + A[i].length + "</td>";

var sum = 0;

for(var k= 0; k < A[i].length; k++){

sum += A[i][k].length;

t += "<td>" + A[i][k] + "-----" + A[i][k].length + "</td>";

}

t += " <td>" +sum+"</td></tr>";

}

t+= "</tbody></table>";

document.write(t);

</script>```

3. Since JavaScript doesn't have multi-dimensional arrays there is no such thing as multi-dimensional array length in JavaScript.

Each element in a JavaScript array can itself be an array giving the equivalent of a multi-dimensional array but the lengths of the arrays iyou add for the second dimension are not forced to be the same and so while you have one length for the first dimentsion of the array each of those elements has its own separate length for the second dimension and so on for as many more arrays within arrays as you build.

var arry = [1
,[1,2,3]
,[1,2]
,[[1,2,3],[4,5,6]]
];

the length of the first dimension is arry.length which will return 4.

The length of the second dimension depends on which element of the first array you are referring to. The first element isn't an array and so doesn't have an array length. The second arry[1].length is 3 and the third and fourth arry[2].length and arry[3].length are both 2.

The last element of the array has a third dimension with both arry[3][0].length and arry[3][1].length being 3.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•