DEV Community

Discussion on: Why you can't break a forEach loop | ByteSize JS

Collapse
 
folke profile image
Folke Lemaitre • Edited

You can use .every() instead and return false whenever you want to break. Return true to keep going

Collapse
 
codenutt profile image
Jared

Interesting! Thank you for your insight. I haven't used every much. Very handy!

Collapse
 
folke profile image
Folke Lemaitre

.some() is probably even better in most cases. Just return true whenever you need to break. No need to return anything when you want to keep going :)

Thread Thread
 
codenutt profile image
Jared

Sweet! May have to do a deep dive article into all the various loop types.

Collapse
 
monfernape profile image
Usman Khalil

This is so helpful

Collapse
 
codenutt profile image
Jared

Thanks! Any other topics you'd like me to tackle?