April 2018
Intermediate to advanced
284 pages
5h 46m
English
| Tip 21 | Write Shorter Loops with Array Methods |
In this tip, you’ll learn to reduce long loops to single lines with array methods.
Before we begin, I want you to know that for loops and for...of loops are good. You’ll want to use them, and you should use them. They’re never going away.
But you should use them less. Why? Well, the reason is simple: They’re unnecessary clutter. You’re writing modern JavaScript, which means you’re going for simplicity, readability, and predictability, and traditional loops don’t meet those goals. Array methods do. Mastering array methods is the fastest way to improve your JavaScript code.
Look at this basic loop that converts an array of price strings into floating point values.
| | const |
Read now
Unlock full access