How make lodash _.replace all occurrence in a string?

Anthony picture Anthony · Apr 5, 2016 · Viewed 49.9k times · Source

How to replace each occurrence of a string pattern in a string by another string?

var text = "azertyazerty";
_.replace(text,"az","qu")

return quertyazerty

Answer

mrstebo picture mrstebo · Sep 22, 2016

You can also do

var text = "azertyazerty";
var result = _.replace(text, /az/g, "qu");