js的数组申明

时间:2021-10-28 15:23:08
 //数组的3种申明方法,如下example
//数组是一种object类型 通过typeof 来检查 //example 1
var arr= new Array("h","k","M","c"); console.log(typeof arr);//object
for( var i in arr){
console.log(arr[i]);
} //example 2
var arr1=Array("hello","你好","大海");
console.log(typeof arr1);//object
for( var i in arr1){
console.log(arr1[i]);
} //example 3
var arr3=["hello","你好","大海"];
console.log(typeof arr3);//object
for(var i in arr3){
console.log(arr3[i]);
} //example 二维数组
var arr4=["hello","你好","大海"]
arr4[]=['这是哪里']; console.log(arr4[][]);