JS案例:使用for...in语句遍历数组

来自CloudWiki
跳转至: 导航搜索
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>数组使用示例</title>
</head><body><pre>
<script type="text/javascript">
		var students,I;
	 	students= new Array("张三","李四","王五","赵六");
		for(i in students){
			//下标从0开始遍历,一直到第4个元素
			document.writeln("第"+(parseInt(i)+1)+"个同学是:"+students[i]);
		} 
</script>
</pre></body></html>