close
紀錄一下之前寫for迴圈時對於 for loop 與 for in 效能的疑惑
var test_arr = [1,2,3,4,5];
var array_length = test_arr .length;
for example:
for (var i = 0; i < array_length ; i++) {
console.log(test_arr [i]);
}
================================
for in example:
for (var key in test_arr ) {
console.log(test_arr [key ]);
}
================================
while example:
while(array_length --){
console.log(test_arr [array_length ]);
}
執行效率結論: while 優於 for loop 優於 for in
全站熱搜
留言列表