1.先定义再赋值
var myArray1 = new Array(); //不定义元素个数 myArray1[0] = "第"; myArray1[1] = "一"; myArray1[2] = "种"; var myArray2 = new Array(3); //定义元素的个数 myArray2[0] = "第"; myArray2[1] = "二"; myArray2[2] = "种";
2.定义数组时同时赋值
var myArray3 = new Array("第","三","种"); //你需要在数组内指定数值或者逻辑值,那么变量类型应该是数值变量或者布尔变量,而不是字符变量 var myArray4 = [ {"num":"1001","name":"jack","age":16}, {"num":"1002","name":"Mary","age":17}, {"num":"1003","name":"Tom","age":19} ]; //注意中括号和大括号的位置
3. 注意
· 数组只有数组长度一个属性
· 如果没有给数组赋值得到的是undefined,打印是”“
· 数组长度不够可以自动扩充,不存在越界的问题