replace all method in javascript code example
Example 1: javascript replace all
const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
console.log(p.replaceAll('dog', 'monkey'));
const regex = /Dog/ig;
console.log(p.replaceAll(regex, 'ferret'));
Example 2: replace all js
let a = 'a a a a aaaa aa a a';
a.replace(/aa/g, 'bb');
Example 3: javascript replace all with variable
function replaceString(oldString, newString, fullString) {
return fullS.split(oldS).join(newS)
}
replaceString('World', 'Web', 'Brave New World')
replaceString('World', 'Web', 'World New World')