Tip 26 | Transform Array Data with reduce() |
In this tip, youâll learn how use reduce() to generate a new array with a different size and shape.
Youâre probably tired of hearing me say that good code is predictable. But itâs true. Array methods are wonderful because you have an idea of the result at a glance without even understanding the callback function. Not only that, but array methods are easier to test and, as youâll see in Tip 32, âWrite Functions for Testability â, itâs much easier to write testable code than it is to add tests to complex code.
Still, there are times when you need to create a new, radically different piece of data from an array. Maybe you need to get a count of certain items. Maybe you want to transform the ...
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.