Created
December 18, 2013 12:49
-
-
Save leeroybrun/8021774 to your computer and use it in GitHub Desktop.
ReplaceAll Javascript function. You can pass a simple string or an array of string to replace. They will be replaced with a single string. (replacement of multiple to multiple not supported)
This file contains hidden or 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
function replaceAll(string, search, replace) { | |
if(Array.isArray(search) === false) { | |
search = [search]; | |
} | |
search.forEach(function(txt) { | |
string = string.split(txt).join(replace); | |
}); | |
return string; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment