how to replace in javascript code example
Example 1: javascript replace string
var str = "JavaScript replace method test";
var res = str.replace("test", "success");
Example 2: javascript replace
var res = str.replace("find", "replace");
Example 3: javascript replace
const p = 'dog dog cat rat';
const regex = /dog/gi;
console.log(p.replace(regex, 'cow'));
console.log(p.replace('dog', 'cow'));
Example 4: replace javascript
let randomtext = "Random text yo!"
let textRegex = /yo!/;
randomtext.replace(textRegex, "is here.");
console.log(randomtext.replace(textRegex, "is here."));
Example 5: replace javascript
let newText = startText.replace("yes", "no")
console.log(newText)
newText = startText.replace(/yes/g, "no")
console.log(newText)
newText = startText.replace(/yes/gi, "no")
console.log(newText)