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.

32 lines
800 B

4 years ago
  1. # `merge()`
  2. The merge method merges the given object into the original collection. If a key in the given object matches a key in the original collection, the given objects value will overwrite the value in the original collection:
  3. ```js
  4. const collection = collect({
  5. id: 1,
  6. price: 29,
  7. });
  8. const merged = collection.merge({
  9. price: 400,
  10. discount: false,
  11. });
  12. merged.all();
  13. // { id: 1, price: 400, discount: false }
  14. ```
  15. If our collection is an array, the values will be appended to the end of the collection:
  16. ```js
  17. const collection = collect(['Unicorn', 'Rainbow']);
  18. const merged = collection.merge(['Sunshine', 'Rainbow']);
  19. merged.all();
  20. // ['Unicorn', 'Rainbow', 'Sunshine', 'Rainbow']
  21. ```
  22. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/merge.js)