replace() method on the string, pass the search string as regular expression with global search, and the replacement string, as arguments. With this setup, replace() method returns a new string with all the occurrences of the search string replaced with replacement string.
1. Given a string value is
"apple" at all occurrences with
str = "apple banana apple cherry guava"; output = str.replace(/apple/g, "mango"); console.log(output);