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.

33 lines
859 B

4 years ago
  1. # `implode()`
  2. The implode method joins the items in a collection. Its arguments depend on the type of items in the collection. If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the "glue" string you wish to place between the values:
  3. ```js
  4. const collection = collect([
  5. {
  6. product: 'Chair',
  7. manufacturer: 'IKEA',
  8. },
  9. {
  10. product: 'Desk',
  11. manufacturer: 'IKEA',
  12. },
  13. {
  14. product: 'Chair',
  15. manufacturer: 'Herman Miller',
  16. },
  17. ]);
  18. collection.implode('product', ',');
  19. // Chair, Desk, Chair
  20. ```
  21. If the collection contains simple strings or numeric values, simply pass the "glue" as the only argument to the method:
  22. ```js
  23. collect([1, 2, 3, 4, 5]).implode('-');
  24. // 1-2-3-4-5
  25. ```
  26. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/implode.js)