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.
630 B
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']