Skip to content

Instantly share code, notes, and snippets.

@mqtik
Created September 24, 2018 22:06
Show Gist options
  • Save mqtik/0062462b8b8619871f6bf1ffd36eb7e5 to your computer and use it in GitHub Desktop.
Save mqtik/0062462b8b8619871f6bf1ffd36eb7e5 to your computer and use it in GitHub Desktop.
Prototype String Replace
String.prototype.deleteWord = function (searchTerm) {
var str = this;
var n = str.search(searchTerm);
while (str.search(searchTerm) > -1) {
n = str.search(searchTerm);
str = str.substring(0, n) + str.substring(n + searchTerm.length, str.length);
}
return str;
}
// Use it like this:
var string = "text is the the cool!!";
string.deleteWord('the'); // Returns text is cool!!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment