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.

29 lines
540 B

4 years ago
  1. # `only()`
  2. The only method returns the items in the collection with the specified keys:
  3. ```js
  4. const collection = collect({
  5. id: 12,
  6. name: 'John Doe',
  7. email: 'john@doe.com',
  8. active: true,
  9. });
  10. const filtered = collection.only(['name', 'email']);
  11. filtered.all();
  12. // { name: 'John Doe', email: 'john@doe.com' }
  13. ```
  14. ```js
  15. collect([1, 2, 3, 4])
  16. .only([2, 12])
  17. .all();
  18. // [2]
  19. ```
  20. > For the inverse of `only`, see the `except` method.
  21. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/only.js)