Automatically gives you the current item, index, and the full array.
Cannot use break or continue — it always goes through the entire array.
More readable for simple array operations.
⚖️ Comparison Table
Feature
for Loop
forEach Loop
Syntax Complexity
Slightly more verbose
Cleaner and shorter
Access to index
Yes
Yes
Access to item
Yes (array[i])
Yes (passed directly)
Can break/continue
✅ Yes
❌ No
Async/Await support
✅ Yes
❌ Not directly supported
Works with non-arrays
✅ Yes
❌ No (only with arrays)
✅ Use for when:
You need to break early or skip iterations.
You need more manual control.
You want to await inside the loop (use for...of in that case).
✅ Use forEach when:
You just want to perform an action on every item.
You want clean and readable code.
You don’t need to exit early or use await.
🔧 Example: Breaking loop
constarr=[1,2,3,4,5];// Using for loopfor (leti=0;i<arr.length;i++){if (arr[i]===3)break;console.log(arr[i]);// 1, 2}// Using forEach (will NOT break)arr.forEach((num)=>{if (num===3)return;// Only skips this iteration, NOT breaksconsole.log(num);// Will still print all except 3});
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (0)