Coming from a PHP background, I am a little spoiled with the str_replace function which you can pass an array of haystacks & needles.
I have yet not seen such a function in Javascript, but I have managed to get the job done, altough ugly, with the below shown code:
return myString.replace(" ", "-").replace("&", ",");
However, as my need to replace certain characters with another character grows, I am sure that there’s much better ways of accomplishing this – both performance-wise and prettier.
So what can I do instead?
You can use this:
Putting that into a function:
Usage example fiddle: http://jsfiddle.net/rtLKr/