Skip to content

Instantly share code, notes, and snippets.

@leeroybrun
Created December 18, 2013 12:49
Show Gist options
  • Save leeroybrun/8021774 to your computer and use it in GitHub Desktop.
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)
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