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.

21 lines
514 B

4 years ago
  1. # `mapInto()`
  2. The mapInto method iterates through the collection and instantiates the given class with each element as a constructor:
  3. ```js
  4. const Player = function (name) {
  5. this.name = name;
  6. };
  7. const collection = collect(['Roberto Firmino', 'Sadio Mané']);
  8. const players = collection.mapInto(Player);
  9. players.all();
  10. // [
  11. // Player { name: 'Roberto Firmino' },
  12. // Player { name: 'Sadio Mané' },
  13. // ]
  14. ```
  15. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/mapInto.js)