Eloi Officiel Eloi Officiel -3 years ago 94
Javascript Question

Advantages to using foreach compared to for

What are the advantages to using a

forEach
loop compared to a
for
loop?

Answer Source

For, foreach. For and foreach differ slightly in performance. They are approximately the same speed. But the foreach loop uses more stack space for local variables.

The for-loop is faster than the foreach-loop if the array must only be accessed once per iteration.

Source: https://www.dotnetperls.com/for-foreach

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download