Created
September 24, 2018 22:06
-
-
Save mqtik/0062462b8b8619871f6bf1ffd36eb7e5 to your computer and use it in GitHub Desktop.
Prototype String Replace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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