string replace global code example
Example 1: javascript replace
var res = str.replace("find", "replace");
Example 2: how to use the replace method in javascript
let string = 'soandso, my name is soandso';
let replaced = string.replace(/soandso/gi, 'Dylan');
console.log(replaced);
Example 3: replace all javascript
str.split(search).join(replacement);
Example 4: javascript replace
const p = 'dog dog cat rat';
const regex = /dog/gi;
console.log(p.replace(regex, 'cow'));
console.log(p.replace('dog', 'cow'));