JavaScript数组-多维数组的困惑

//javascript中没有多维数组的概念
var aa = new Array();
aa[0] = 1;
aa["tt"] = [0,1];//javascript在用负数,浮点数,(或布尔型,对象,其他值时),javascript会将它转换为一个字符串,用生成的字符串作为对象的属性名字,而不是定义了一个新的数组元素
aa["bb"] = [2,3];
//遍历数组中的所有属性,不仅仅遍历数组元素
for(var i in aa){
document.write(aa[i]);
}
document.write(aa.length);
document.write(aa["tt"].length);

var myArray=new Array(); 
for(var i=0;i<10;i++){ 
myArray[i]=new Array(); 
myArray[i][0]=Math.floor(Math.random()*10); 
myArray[i][1]=Math.floor(Math.random()*10); 
myArray[i][2]=Math.floor(Math.random()*10); 
myArray[i][3]=Math.floor(Math.random()*10); 
myArray[i][4]=Math.floor(Math.random()*10); 
myArray[i][5]=Math.floor(Math.random()*10); 
myArray[i][6]=Math.floor(Math.random()*10); 
myArray[i][7]=Math.floor(Math.random()*10); 
myArray[i][8]=Math.floor(Math.random()*10); 

myArray[10.2] = 11;
myArray[9][9] = 22;
 
myArray.sort(function(x,y){ 
return(x[0]==y[0])?((x[4]==y[4])?(x[8]-y[8]):(x[4]-y[4])):(x[2]-y[2]) 
});
var count = 0;
for(var i=0;i<myArray.length;i++)

document.write(myArray[i].join(",")+"<br/>");
for(var j = 0; j<myArray[i].length;j++){
document.write(myArray[i][j]+"H"+"</br>"); 
count++;
}
}
document.write(myArray.length);//
document.write(myArray[0].length);
document.write(count);

posted @ 2011-06-30 11:16  Mygirl  阅读(1714)  评论(0编辑  收藏  举报