So if I just want to replace the first instance of a text pattern in a string when reading it from left to right, and lodash is part of the stack, then the _.replace method could be used to do just that very easily. Just pass in the string as the first argument, followed by the pattern to look for, and then finally the text to replace the pattern to look for.
The text pattren to look for can be a string or a regular expression. More on that in the next session.
If I want to replace more than one instance with the lodash _.replace method, that can be done by passing a regular expression with the global flag set.
Regular expressions come in handy when it comes to replacing not just all instances of a pattern, but also more complex patterns that are not static fixed collections of characters, and more. I will not be getting into detail with regular expressions here, as I have wrote a post on regex where I do just that.
Some methods in lodash do work a littler differently, for example the _.map method is a collection method that will work well on most objects in general while the Array.map method is just an Array prototype method. However when it comes to _.replace there does not seem to be much of anything that really sets it apart.
So the above basic example can also be done with the native String.replace like this.
And regular expressions can be done with it as well.