I recommend to always use for … of in ES6.

  • It works on any iterable.
  • It supports all kinds of control flow in the loop body, like continue, break, return, yield and await.

Also I personally find it more readable, but that comes down to preference. Some people think forEach is a more functional style, but that's wrong – it has no result value and is all about doing side effects, so an imperative-looking loop fits that purpose better.

Performance is not a concern: in modern engines all loop styles are equivalent.

Answer from Bergi on Stack Overflow
🌐
Medium
medium.com › @trig79 › javascript-the-early-lessons-for-vs-foreach-vs-for-of-loops-iteration-which-one-is-better-b557f385045
JavaScript The Early Lessons: For Vs forEach Vs For Of. Loops & Iteration, Which One Is Better? | by Trig | Medium
April 12, 2022 - Unlike above where once a condition is met we can enter a ‘break’ clause and the loop would end, forEach() doesn’t work like that. In the case where you may handle 10000+ rows of data, what happens when we find the result in the first few 100 rows? Well, nothing we have to sit and wait for the loop to iterate through every single row before it finishes.
Top answer
1 of 2
222

I recommend to always use for … of in ES6.

  • It works on any iterable.
  • It supports all kinds of control flow in the loop body, like continue, break, return, yield and await.

Also I personally find it more readable, but that comes down to preference. Some people think forEach is a more functional style, but that's wrong – it has no result value and is all about doing side effects, so an imperative-looking loop fits that purpose better.

Performance is not a concern: in modern engines all loop styles are equivalent.

2 of 2
83

This is a very interesting question which has been discussed in many other sites. I'll post the basics of what I have read.

ForEach exclusively belong to the royal family of Arrays. The forEach method was introduced with lineage to the prototypal inheritance of Array object! Needless to say, the forEach clause works only with those data structure which are Arrays. The method basically iterates over the elements of the array and executes a callback function [basically some executable function/ fun activity].


The for-of loop is adequately new to the JS world and packs in super-powers! Voilaaaaaaa! The for-of loop creates a loop iterating over iterable member objects. The list is an extensive one such as

  • Array
  • Map
  • Set
  • String
  • TypedArray
  • Other W3C classes

You need to know that this bad-ass boy emerged with the birth of ES6 in 2015. So, it offers plenty of flexibility in usage


Performance

In performance, for...of is faster than forEach. Results can be found here

forEach is 24% slower than for...of


Update

There are several other iterable classes in the W3C specification, like FileList, as I mentioned above. And in recent drafts of W3C (around when ES6 was released), collections like HTMLCollection and NodeList now implement forEach() as well, not just Array anymore. By @Patrick Roberts


Source Links:

  • https://codeburst.io/foreach-vs-for-of-vs-for-in-tug-of-for-d8f935396648
  • https://www.reddit.com/r/javascript/comments/4spd5b/forof_vs_foreach/
🌐
The Code Barbarian
thecodebarbarian.com › for-vs-for-each-vs-for-in-vs-for-of-in-javascript
For vs forEach() vs for/in vs for/of in JavaScript
February 20, 2019 - Generally, for/of is the most robust way to iterate over an array in JavaScript. It is more concise than a conventional for loop and doesn't have as many edge cases as for/in and forEach().
🌐
Leanylabs
leanylabs.com › blog › js-foreach-map-reduce-vs-for-for_of
Performance of JavaScript .forEach, .map and .reduce vs for and for..of
Imperative code is a lot more verbose in most cases. Five code lines for a simple sum are too much, and reduce is just a one-liner. On the other hand, .forEach is almost the same as for or for..of, only slower.
🌐
Medium
dev-aditya.medium.com › for-of-vs-foreach-which-one-is-better-25de7e8e9ff3
for...of vs forEach Which one is better? | by Aditya Yadav | Medium
October 3, 2024 - No Callback: The for...of loop does not require a callback function, eliminating the memory overhead associated with function creation. Simpler Scope: Since there’s no additional function scope, there’s less risk of inadvertently retaining references to variables, aiding garbage collection. ... Internal Iteration: The iteration logic is handled internally by the forEach method.
🌐
DEV Community
dev.to › basedenergy › for-loops-vs-foreach-a-far-reach-59j1
For Loops vs. forEach: A Far Reach! - DEV Community
November 1, 2018 - Less chance for small errors in code since you don't have to specify a condition statement. While I really don't want to catapult myself into this debate, and I typically avoid talking politics, I have to say that I do have a preference here... I think that in most circumstances where an array needs to be looped through, the forEach() method is better practice! It looks a lot nicer and makes code more readable and maintainable. One of the only times I would use a for loop is if I knew I needed to break out of the loop early.
Find elsewhere
🌐
Quora
quora.com › Do-you-think-the-forEach-method-is-better-than-using-a-for-loop
Do you think the .forEach() method is better than using a for loop? - Quora
Each .forEach is significantly slower than doing a for loop. ... It is significantly faster than doing a forEach. Why? Because each forEach call is a new function, also, it calls the length of the list only once.
🌐
JavaScript in Plain English
javascript.plainenglish.io › when-i-use-map-vs-for-of-vs-foreach-and-why-it-matters-43b2c959063b
When I Use map vs for...of vs forEach — And Why It Matters | JavaScript in Plain English
July 16, 2025 - | |---------------|-----------------------------|----------------|------------------|-------------------------------------| | map | Transform & return array | ✅ Yes | 🚫 Not natively | You need a new array (pure logic) | | forEach | Loop for side effects | ❌ No | 🚫 No | You don’t care about the return | | for...of | Loop with flexibility | ✅ Yes (manual) | ✅ Yes | You need async/await or `break` |
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › difference-between-foreach-and-for-loop-in-javascript
Difference between forEach and for loop in Javascript - GeeksforGeeks
August 22, 2024 - In JavaScript, both forEach and ... behavior. forEach is a higher-order function that simplifies iteration with built-in array methods, while for loops offer more control, flexibility, and broader application....
🌐
Fjolt
fjolt.com › article › javascript-each-vs-foreach-vs-in
Javascript loops: for vs forEach vs for.. in vs for.. of
While forEach is definitely an easy way to iterate over an array, it’s not always the best. ## Using for loops on iterables There are three types of for loops to run over iterables in Javascript:
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › array › javascript iteration methods comparison
What is the difference between JavaScript's for...in, for...of and forEach? - 30 seconds of code
June 12, 2021 - While Array.prototype.forEach() only iterates over arrays, it can access both the value and the index of each element while iterating. ['a', 'b', 'c'].forEach( val => console.log(val) // a, b, c (array values) ); ['a', 'b', 'c'].forEach( (val, i) => console.log(i) // 0, 1, 2 (array indexes) ); ... Learn how to execute a function for each element of an array, starting from the last one.
🌐
Better Programming
betterprogramming.pub › difference-between-javascript-loops-for-foreach-for-of-and-for-in-91cd8fe884fd
Difference Between JavaScript Loops: For, ForEach(), For…of, and For…in | by Sylwia Vargas | Better Programming
February 4, 2021 - There’s another, more obscure benefit: The temporary variable (currentElement in the example above) is locally scoped, whereas that is not so in the for...of loop. See here: In the above example, we can see that forEach has not overwritten the value of the num variable declared outside of its scope, whereas that was not the case with the for...of loop.
🌐
2ality
2ality.com › 2021 › 01 › looping-over-arrays.html
Looping over Arrays: `for` vs. `for-in` vs. `.forEach()` vs. `for-of`
January 7, 2021 - As we have seen, the for-of loop beats for, for-in, and .forEach() w.r.t.
🌐
C# Corner
c-sharpcorner.com › article › for-vs-foreach-in-c-sharp
For Vs Foreach In C#
August 24, 2022 - As I said, a foreach loop creates a copy of a collection, so in this loop, the ‘item’ is not referencing to the array elements; it’s just a temporary variable and you cannot assign a value to it. Also, when it comes to performance, then ‘foreach’ takes much time as compared to the ‘for’ loop because internally, it uses extra memory space, as well as, it uses GetEnumarator() and Next() methods of IEnumerables.
🌐
Hashnode
dsvynarenko.hashnode.dev › nodejs-performance-1-forof-vs-foreach
Node.js Performance Analysis: Comparing for...of vs forEach() Methods
April 11, 2024 - In a comparison of the performance of imperative and functional approaches in Node.js, the imperative for...of operator demonstrates superior speed due (~4 times faster) to its direct iteration process.
🌐
Medium
osgoodgunawan.medium.com › for-loop-vs-foreach-vs-for-in-vs-for-of-a106612cb49
For loop vs. forEach vs. for…in vs. for…of | by Osgood Gunawan | Medium
December 7, 2020 - Usually utilizing to iterate values in an array of most array-like objects such as maps. Unlike forEach(), you can use “break,” “continue,” and “return.”Two advantages of ‘for-of’ over ‘for-in’ are that.