分类: JavaScript
2013-12-22 23:53:56
/*
var box = new Array();//声明空数组
alert(typeof(box));//数组属于对象object类型
*/
/*
var box= new Array("hans","20","吉林");
alert(box);
alert(box[0]);
alert(box[2]);
*/
//创建数组,包含10个元素
/*
var box = new Array(10);
alert(box);
box[3]='hans';//赋值
alert(box);
*/
//2.字面量方式创建数组
/*
var box=['hans',21,'吉林'];//额外逗号会让IE获取,而产生错误
alert(box);
*/
/*
var box=['hans',21,'吉林'];
box[1]=100; //修改
alert(box);
*/
//用字符串做索引
/*
var box=[];
box["name"]="hans";
box["age"]=10;
alert(box.name);
alert(box.age);
*/
//数组元素类型可以多种
var box=[
{name:'hans',age:21},
[2,4,5,new Object()],
25+25,
new Array(1,3,7)
]
alert(box);
alert(box[0].name)