What is the output of following code?
const str = "Butterfly likes Butter";
const result = str.replace("Butter", "Fire");
console.log(result);
----o----
Output is "Firefly likes Butter"
.
String replace()
method replaces only the first match. If we need to replace all matches, ES12 comes with replaceAll()
method.