JS 迴圈與效能 Admin 收錄於 Note2023-11-21 目錄 JS 常見的 for 迴圈參考資料JS 常見的 for 迴圈 以下由執行速度的快到慢排序for-loop-cached1 2 3 4 const listSize = yourList.length; // 精華 for (let index = 0; index < listSize; index++) { // ... }for-loop1 2 3 for (let index = 0; index < yourList.length; index++) { // ... }forEach1 2 3 yourList.forEach((element) => { // ... });for-of1 2 3 for (const element of yourList) { // ... }參考資料 https://dev.to/siddiqus/which-for-loop-is-the-fastest-in-javascript-4hdf