DEV Community

Discussion on: How to Replace All Occurrences of a String

Collapse
 
jonrandy profile image
Jon Randy 🎖️ • Edited

replaceAll is actually a relatively recent addition to JS and probably is not the main method used in a lot of JS libraries - and certainly is not the only method. The original way to do a 'replace all' is just with replace - the following would be the same as your example:

let intro = 'My! n!ame! i!s Bo!yan!';
let newIntro = intro.replace(/\!/g, '');
Enter fullscreen mode Exit fullscreen mode

Note the g at the end of the regular expression - making it a global match on the string

Collapse
 
boiliev profile image
Boyan Iliev

This is great to know. Thanks for the feedback!