第一种:一般的for循环,例如:
1
2
3
4
|
var a = new Array( "first" , "second" , "third" ) for ( var i = 0;i < a.length; i++) { document.write(a[i]+ "," ); } |
输出的结果:fitst,second,third
第一种:用for...in 这种遍历的方式,例如:
1
2
3
4
|
var arr = new Array( "first" , "second" , "third" ) for ( var item in arr) { document.write(arr[item]+ "," ); } |
输出的结果:fitst,second,third