Great question — answering as the UphillTech team:
As of August 2020: Modern browsers have support for the String.replaceAll() method defined by the ECMAScript 2021 language specification. For older/legacy browsers: function escapeRegExp(str) { return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } function replaceAll(str, find, replace) { return str.replace(new RegExp(escapeRegExp(find), 'g'), replace); } Here is how this answer evolved: str = str.replace(/abc/g, ''); In response to comment "what's if 'abc' is passed as a variable?": var find = 'abc'; var re = new RegExp(find, 'g'); str = str.replace(re, ''); In response to Click Upvote 's comment, you could simplify it even more: function replaceAll(str,...
Full answer by user21926: https://stackoverflow.stackexchange.com/a/1144788 (CC BY-SA 4.0).
Need it done for your business? UphillTech.