How to use the javascript string replace

The replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.

var str = "Replace here!!";
var res = str.replace("here", "");

Replace all occurrences of a string

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


Add a Comment

Your email address will not be published. Required fields are marked *