How to replace white space with the equivalent special character in string? : <p>Say we have:</p>

<pre><code>Saudi Arabia
</code></pre>

<p>If I do:</p>

<pre><code>loc.replace(/ /g,''));
</code></pre>

<p>Becomes:</p>

<pre><code>SaudiArabia
</code></pre>

<p>What if I want to replace the white space with <code>&amp;nbsp</code>?</p>

<p>Tried:</p>

<pre><code>loc.replace(/ /g,'&amp;nbsp')
</code></pre>

<p>I am looking for </p>

<pre><code>Saudi&amp;nbspArabia
</code></pre>
