JS Daily 9 - String Replace Method

Last updated on 29 Nov, 2020

What is the output of following code?

const str = "Butterfly likes Butter";
const result = str.replace("Butter", "Fire");

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.

--- ○ ---
Joby Joseph
Web Architect