my-idlers/node_modules/collect.js/docs/api/flatMap.md
cp6 fd22b0bf58 V2 (Laravel re-make)
V2 (Laravel re-make)
2022-03-06 02:02:12 +11:00

630 B

flatMap()

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:

const collection = collect([
  {
    name: 'Sadio Mané',
    number: 10,
  },
  {
    name: 'Mohamed Salah',
    number: 11,
  },
]);

const flatMapped = collection.flatMap(value => value.name.toUpperCase());

flatMapped.all();

// ['SADIO MANÉ', 'MOHAMED SALAH']

View source on GitHub