JavaScript中遍历数组中元素的两种方法

2015-03-27 20:02:20

<!doctype html>

<html lang="en">

 <head>

  <meta charset="UTF-8">

  <meta name="Generator" content="EditPlus®">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

  <title>Document</title>

  <script>

  var arr= new Array('good boy',2,7,4,7,3,true);

	/*使用for...in...遍历数组*/

	for(var i in arr){

		document.write('第'+i+'个元素是'+arr[i]+'<br/>');//输出元素值;

	}



	/*使用for...in...遍历数组*/

	for(var s=0;s<arr.length;s++){

		document.write('第'+s+'个元素是'+arr[s]+'<br/>');//输出元素值

	}

  </script>

 </head>

 <body>

  

 </body>

</html>

  

你可能感兴趣的:(JavaScript)