1. 程式人生 > >遍歷數組的常用方法

遍歷數組的常用方法

event none second div src pan gif cli one

1.最傳統方法 for循環

技術分享圖片
 1  var arr = ["first","second","third","fourth",3,5,8];
 2  for(var i = 0; i < arr.length;i++){
 3         console.log(arr[i]);
 4     }
 5     //輸出:
 6      first
 7      second
 8      third
 9      fourth
10      3
11      5
12      8
View Code

遍歷數組的常用方法