Make string comma delimited in JavaScript
<p>I have a string:</p>
<pre><code>var myStr = 'This is a test';
</code></pre>
<p>I would like to make it comma delimited via JavaScript, like so:</p>
<pre><code>var myNewStr = 'This, is, a, test';
</code></pre>
<p>What is the best way to accomplish this via JavaScript?</p>
<p>I know I can trim the commas like so:</p>
<pre><code>var myStr = myNewStr.split(',');
</code></pre>
<p>And that would give me this:</p>
<pre><code>myStr = 'This is a test';
</code></pre>
<p>But I am wanting to do the opposite of course, by adding commas.</p>