JavaScript中遍歷數(shù)組中元素的兩種方法
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...遍歷數(shù)組*/
for(var i in arr){
document.write('第'+i+'個元素是'+arr[i]+'<br/>');//輸出元素值;
}
/*使用for...in...遍歷數(shù)組*/
for(var s=0;s<arr.length;s++){
document.write('第'+s+'個元素是'+arr[s]+'<br/>');//輸出元素值
}
</script>
</head>
<body>
</body>
</html>

浙公網(wǎng)安備 33010602011771號