1// Chrome 85+
2str.replaceAll(val, replace_val);
3// Older browsers
4str.replace(/val/g, replace_val);
1const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
2
3console.log(p.replaceAll('dog', 'monkey'));
4// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
1const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
2
3console.log(p.replaceAll('dog', 'monkey'));
4// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
5
6// global flag required when calling replaceAll with regex
7const regex = /Dog/ig;
8console.log(p.replaceAll(regex, 'ferret'));
9// expected output: "The quick brown fox jumps over the lazy ferret. If the ferret reacted, was it really lazy?"
10
1const p = 'The quick brown fox jumps over the lazy dog. If the dog reacted, was it really lazy?';
2
3console.log(p.replaceAll('dog', 'monkey'));
4
5// expected output: "The quick brown fox jumps over the lazy monkey. If the monkey reacted, was it really lazy?"
6
7
8
9