The array.flatMap() method gives you the ability to map, but also to remove or even add new items in the resulting mapped array. By controlling the number of array items you return from the callback, you can do more than simple flattening. The method accepts a second, optional, argument indicating the this value inside of the callback.

4m read timeFrom dmitripavlutin.com
Post cover image
Table of contents
1. Smarter mapper2. array.flatMap()3. Conclusion
2 Comments

Sort: