第一种最常用的:for循环
for(j = 0; j < arr.length; j++) { }
优化版for循环
for(j = 0,len=arr.length; j < len; j++) { }
对于数组较大时,优化比较明显;
第二种:foreach
arr.forEach(function(e){ });
第三种:for ……in
var arr = new Array("first", "second", "third") for(var item in arr) { document.write(arr[item]+","); }
for……in 的效率比较低
第四种:map 遍历
arr.map(function(n){ });
第五种:for……of 遍历(需要ES6支持)
for(let value of arr) { });
for、map是比较常用的两种方法,性能也还行。