You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
630 B

4 years ago
  1. # `flatMap()`
  2. The flatMap method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items. Then, the array is flattened by a level:
  3. ```js
  4. const collection = collect([
  5. {
  6. name: 'Sadio Mané',
  7. number: 10,
  8. },
  9. {
  10. name: 'Mohamed Salah',
  11. number: 11,
  12. },
  13. ]);
  14. const flatMapped = collection.flatMap(value => value.name.toUpperCase());
  15. flatMapped.all();
  16. // ['SADIO MANÉ', 'MOHAMED SALAH']
  17. ```
  18. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/flatMap.js)