mirror of
https://github.com/cp6/my-idlers.git
synced 2025-04-20 10:08:35 +00:00
521 B
521 B
mapInto()
The mapInto method iterates through the collection and instantiates the given class with each element as a constructor:
const Player = function (name) {
this.name = name;
};
const collection = collect([
'Roberto Firmino',
'Sadio Mané',
]);
const players = collection.mapInto(Player);
players.all();
// [
// Player { name: 'Roberto Firmino' },
// Player { name: 'Sadio Mané' },
// ]