<script>
// 创建一个多维数组
//设置数组长度
var arrLength = 3;
//创建数组
var multiArray = new Array(arrLength);
// console.log(multiArray);
for(var i=0;i<multiArray.length;i++){
multiArray[i] = new Array(arrLength);
}
//给第一个数组索引添加项
multiArray[0][0] = "apple";
multiArray[0][1] = "banana";
multiArray[0][2] = "cherry";
//给第二个数组索引添加项
multiArray[1][0] = 33;
multiArray[1][1] = 44;
multiArray[1][2] = 55;
//给第三个数组索引添加项
multiArray[2][0] = ["test","again"];
multiArray[2][1] = ["Java","script"];
multiArray[2][2] = ["read","books"];
console.log(multiArray);
console.log(multiArray[1]);
console.log(multiArray[2]);
console.log(multiArray[2][1]);
var table = new Array(5);
table[0] = [45.89,4,34,9998.99,5];
table[1] = [5,9,46,35,555];
table[2] = [11,22,33,55,66];
document.write(table);
</script>
创建一个多维数组(一个数组的数组)
最新推荐文章于 2024-06-12 21:21:35 发布