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.

22 lines
520 B

4 years ago
  1. # `replace()`
  2. The replace method behaves similarly to merge; however, in addition to overwriting matching items with string keys, the replace method will also overwrite items in the collection that have matching numeric keys:
  3. ```js
  4. const collection = collect({
  5. name: 'Bob',
  6. });
  7. const replaced = collection.replace({
  8. name: 'John',
  9. number: 45,
  10. });
  11. replaced.all();
  12. // {
  13. // name: 'John',
  14. // number: 45,
  15. // }
  16. ```
  17. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/replace.js)