本文来介绍JavaScript中的数组,主要是数组的创建数组的读取数据。
<! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
</head>
<body>
<script type ="text/javascript">
var people = new Array("张三","李四","王二","Lucy","Tom");
document.write(people[0]);
</script>
</body>
</html>
总结:
1. 通过Array创建数组,用小括号表示,里面每个元素用逗号隔开
2. 数组是通过索引来找元素的,例如上面people[0]代表“张三”
3. 数组越界,例如people[5],前端页面显示undefined