by @saigowthamr

How to replace all occurrences in a string JavaScript

Home » javascript » How to replace all occurrences in a string JavaScript

To replace all occurrences of a string we can use the replace() method in JavaScript.

Here is an example, which replaces all occurrences of an ola in the following string.

const str = "how ola are ola you ola";
                        // (search , replacement)
const replaced = str.replace(/ola/gi, "");

console.log(replaced);

Output:

how are you

Best Web Development courses