[javascript]代码库
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>JS中的数组第二种定义方式</title>
</head>
<body>
<script type="text/javascript">
//创建数组对象
//var arr = new Array();
var arr = new Array(3);
//alert(arr.length);
//动态的给数组中添加元素
arr[1] = 123;
arr[3] = true;
arr[5] = null;
arr[7] = "itcast";
arr[8] = undefined;
//遍历数组
for( var i=0;i<arr.length;i++ ){
document.write(arr[i]+",");
}
document.write("<hr />");
//for-in
for( x in arr ){
document.write(arr[x]+",");
}
document.write("<hr />");
//定义了二维数组
var arr2 = [[1,2,3],["abc","bbbb"],[true,false]];
for( var i=0;i<arr2.length;i++ ){
for( var j=0;j<arr2[i].length;j++ ){
document.write(arr2[i][j]+",");
}
document.write("<br />");
}
</script>
</body>
</html>