replace spaces with commas with javascript
<p>I have a string with keywords and I need to check if this string contains spaces and if yes replace them with commas.<br>
the string can be something like "keyword1   keyword2 ,keyword3  keyword4,keyword5"<br>
or any other combination of spaces and commas.
the final result should be a string of keywords separated by commas without any spacing<br> like in the following <strong>"keyword1,keyword2,keyword3,keyword4,keyword5"</strong>.<br>
for that I tried to do <code>$("#strId").split('').join(',')</code><br>
This done the job but I notice that if I have a string which contains more then one space between each keyword I got multiple commas like that:<br>
original string=(keyword1    keyword2      keyword3)<br>
result string =(keyword1,,,,,,keyword2,,,,,,keyword3)<br>
and I need that it will be with single comma only between each word.
I will appreciate a help on this issue</p>

<p>Thanks </p>
