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.

25 lines
681 B

4 years ago
  1. # `mergeRecursive()`
  2. The mergeRecursive method merges the given array or collection recursively with the original collection. If a string key in the given items matches a string key in the original collection, then the values for these keys are merged together into an array, and this is done recursively:
  3. ```js
  4. const collection = collect({
  5. product_id: 1,
  6. price: 100,
  7. });
  8. const merged = collection.mergeRecursive({
  9. product_id: 2,
  10. price: 200,
  11. discount: false,
  12. });
  13. merged.all();
  14. // {
  15. // product_id: [1, 2],
  16. // price: [100, 200],
  17. // discount: false,
  18. // }
  19. ```
  20. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/mergeRecursive.js)