Monday, August 12, 2019

How to replace all the entries in a string in Javascript? like replaceAll?

This should do the trick by adding a new method (replaceAll) to the String prototype.

String.prototype.replaceAll = function(search, replacement){
            return this.replace(new RegExp(search, 'g'), replacement);
        };

No comments:

Post a Comment