<script type="text/javascript">
//为Array赋值的方法
function showarray() {
var array = new Array();
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
//虽然在定义Array时声明了数组的元素个数,但是可以随意扩充
var array = new Array(4);
array[0] = 1;
array[1] = 2;
array[2] = 3;
array[3] = 4;
array[4] = 5;
array[40] = 40;
//var array = new Array('张三', '李四', '王五', '赵六');
Array[0] = '张三';
Array[1] = '李四';
Array[2] = '王五';
Array[3] = '赵六';
//Array对象可以存储不止一种类型的数据
var array = new Array('张三', 1, '王五', 2);
var array = ['张三', 1, '王五', 2];
for (var i = 0; i < array.length; i++) {
document.write(array[i]);
}
array[1] = '李四';
for (var i = 0; i < array.length; i++) {
document.write(array[i]);
}
}
</script>
</head>
<body>
<input type="button" value="dian" onclick="showarray()" />
</body>
</html>