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.

16 lines
613 B

4 years ago
  1. # `transform()`
  2. The transform method iterates over the collection and calls the given callback with each item in the collection. The items in the collection will be replaced by the values returned by the callback:
  3. ```js
  4. const collection = collect([1, 2, 3, 4, 5]);
  5. collection.transform((item, key) => item * 2);
  6. collection.all();
  7. // [2, 4, 6, 8, 10]
  8. ```
  9. > Unlike most other collection methods, `transform` modifies the collection itself. If you wish to create a new collection instead, use the `map` method.
  10. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/transform.js)