DEV Community

loading...

Discussion on: Don’t use for loop for JavaScript Arrays

Collapse
joeattardi profile image
Joe Attardi

There are still perfectly valid use cases for the for loop. For example, if you want to break out of the loop early there’s the break keyword.

Or if you want to not iterate over the items of an array, but rather just repeat something a certain number of times, a for loop is useful there too.

A for loop also lets you have more complex logic for when you should continue looping. Remember that for loops are not only used for iterating over an array.

Collapse
sharmakushal profile image

Some comments have been hidden by the post's author - find out more

Forem Open with the Forem app