<script type="text/javascript"> var names = new Array(); names[0] = "张三"; names[1] = "李四"; names[2] = "王五"; names[3] = "赵六"; //键值对集合是没有length长度的,所以遍历的时候使用forin循环来遍历。 //对于普通数组遍历的时候要使用for循环来遍历。 for (var key in names) { alert(key + ' ' + names[key]); } var objects = new Array(); objects['zs'] = "张三"; objects['ls'] = "李四"; objects['ww'] = "王五"; objects['zl'] = "赵六"; //键值对集合也可以理解成为一个对象 alert(objects.zs); alert(objects.ls); alert(objects.ww); alert(objects.zl); </script>