Tip 27 | Reduce Loop Clutter with for...in and for...each |
In this tip, you’ll learn how to maintain clarity with loops over iterables using for...in and over objects using for...of.
Hopefully by now you’re convinced that array methods can handle most of your iterations in clear and predictable ways. Sometimes, however, an array method may be either inefficient or cumbersome.
There may be times you want to exit out of a loop when a result doesn’t match what you need. In those cases, it makes no sense to keep iterating over information.
Alternatively, an array method may be overly complex when you’re working with a collection that isn’t an array. Remember that just because a structure isn’t an array doesn’t mean you can’t use array methods. If ...
Get Simplifying JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.