I am Hack Sparrow
Captain of the Internets.

The For Loop vs the For Each Loop in JavaScript

When do you use the For Loop and the For Each Loop in JavaScript? The answers to that question depends entirely on your requirement. The For Loop is best for iterating over name-value pairs, and the For Each Loop best for iterating over values, for example arrays. Neither is better or worse than the other, but understanding how they work will help you make the best use of them. Observe the examples below. ...