# 二维数组的长度

shnewtouch 2004-10-22 08:51:16
var company=new Array(new Array(),new Array());
company是一个二维数组，我想知道他的长度，比如:company[0]的长度。怎么实现呢？谢谢了！
...全文
1380 9 打赏 收藏 举报

9 条回复

shnewtouch 2004-10-22
• 打赏
• 举报

<script language="javascript">
var company=new Array(new Array(),new Array());
company[0][0]="a";
company[0][1]="b";
company[0][2]="c";
company[1][0]="d";
company[2][0]="e";
company[3][0]="f";
var i=0;
for(i=0;i<company[i].length;i++)
document.write(company[i][0]);
</script>

shnewtouch 2004-10-22
• 打赏
• 举报

• 打赏
• 举报

var company=new Array(new Array(),new Array());

company[0][0] = "a1";
company[0][1] = "a2";

<SCRIPT LANGUAGE="JavaScript1.2">

myFish = ["angel", "clown", "mandarin", "surgeon"];
document.writeln("myFish: " + myFish + "<BR>");

removed = myFish.splice(2, 0, "drum");
document.writeln("After adding 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>");

removed = myFish.splice(3, 1)
document.writeln("After removing 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>");

removed = myFish.splice(2, 1, "trumpet")
document.writeln("After replacing 1: " + myFish);
document.writeln("removed is: " + removed + "<BR>");

removed = myFish.splice(0, 2, "parrot", "anemone", "blue")
document.writeln("After replacing 2: " + myFish);
document.writeln("removed is: " + removed);

</SCRIPT>

This script displays:

myFish: ["angel", "clown", "mandarin", "surgeon"]

After adding 1: ["angel", "clown", "drum", "mandarin", "surgeon"]
removed is: undefined

After removing 1: ["angel", "clown", "drum", "surgeon"]
removed is: mandarin

After replacing 1: ["angel", "clown", "trumpet", "surgeon"]
removed is: drum

After replacing 2: ["parrot", "anemone", "blue", "trumpet", "surgeon"]
removed is: ["angel", "clown"]
stefli 2004-10-22
• 打赏
• 举报

company[0].length

fason 2004-10-22
• 打赏
• 举报

shnewtouch 2004-10-22
• 打赏
• 举报

fason 2004-10-22
• 打赏
• 举报

JavaScript没有严格意义上的多维数组。

micker 2004-10-22
• 打赏
• 举报

var company=new Array(new Array(),new Array());

company[0].length;

• 打赏
• 举报

var company = new Array();

company[0] = new Array();
company[0][0] = "a";
company[0][1] = "b";
company[0][2] = "c";

company[1] = new Array();
company[1][0] = "d";

company[2] = new Array();
company[2][0] = "e";

company[3] = new Array();
company[3][0] = "f";

for( i = 0; i < company.length; i++ )
{
for ( j = 0; j < company[i].length; j++ )
{
document.writeln("company[" + i + "][" + j + "] = " + company[i][j] + "<br>");
}
}

8.7w+

Web 开发 JavaScript

2004-10-22 08:51