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
573 B

4 years ago
  1. # `replaceRecursive()`
  2. This method works like replace, but it will recurse into arrays and apply the same replacement process to the inner values:
  3. ```js
  4. const collection = collect([
  5. 'Matip',
  6. 'van Dijk',
  7. [
  8. 'Mané',
  9. 'Firmino',
  10. 'Salah',
  11. ],
  12. ]);
  13. const replaced = collection.replaceRecursive({
  14. 0: 'Gomez',
  15. 2: { 1: 'Origi' },
  16. });
  17. replaced.all();
  18. // {
  19. // 0: 'Gomez',
  20. // 1: 'van Dijk',
  21. // 2: { 0: 'Mané', 1: 'Origi', 2: 'Salah' },
  22. // }
  23. ```
  24. [View source on GitHub](https://github.com/ecrmnn/collect.js/blob/master/src/methods/replaceRecursive.js)