1 //通过自面量创建数组 2 var arr1=[1,'abc',true,{a:1}]; 3 for(i in arr1){ 4 alert(arr1[i]+":"+(typeof arr1[i])); 5 } 6 alert(typeof arr1);//Object数组也是一个对象 7 8 //通过构造器创建数组 9 var arr2=new Array(3,4,5); 10 for(var i=0;i<arr2.length;i++){ 11 alert("arr2["+i+"]:"+arr2[i]); 12 } 13 14 //反置数组 15 var arr3=arr2.reverse(); 16 for(var i=0;i<arr3.length;i++){ 17 alert("arr3["+i+"]:"+arr3[i]); 18 } 19 20 //arr2.reverse()执行后,数组会发生改变 21 for(var i=0;i<arr2.length;i++){ 22 alert("arr2["+i+"]:"+arr2[i]); 23 } 24 25 //二维数组的使用 26 var arr4=[[1,2],[3,4],[5,6,'a'],[7,8,9]]; 27 for(var i=0;i<arr4.length;i++){ 28 for(var j=0;j<arr4[i].length;j++){ 29 alert(arr4[i][j]); 30 } 31 }