string replace js all code example
Example 1: js string replaceall
str.replaceAll(val, replace_val);
str.replace(/val/g, replace_val);
Example 2: 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 3: js replace all substrings
str.replace(/abc/g, '');
Example 4: replace all js
let a = 'a a a a aaaa aa a a';
a.replace(/aa/g, 'bb');
Example 5: str replace javascript all
str.replace(/abc/g, '');