DEV Community

Discussion on: for of, for in or forEach?

Collapse
 
mnlfischer profile image
Manuel • Edited

The for and for/in looping constructs give you access to the index in the array, not the actual element.

With forEach() and for/of, you get access to the array element itself.

Note:

  • forEach keeps the variable’s scope to the block
  • lower chance of accidental errors with forEach
  • forEach is easier to read
  • you can break out of a for loop earlier