String replacement in JavaScript
<p>I have two strings:</p>

<pre><code>var str1 = '8***8***';
var str2 = '898-8293';
</code></pre>

<p>How can i wrap the digits found in string one, with html elements on the second string, like so:</p>

<pre><code>'&lt;b&gt;8&lt;/b&gt;98-&lt;b&gt;8&lt;/b&gt;293'
</code></pre>

<p>Note: Not all '8' digits are wrapped.</p>

<p>[EDIT]</p>

<p>Thanks to Soufiane Hassou and voyager the following worked:</p>

<pre><code>&lt;script type="text/javascript"&gt;
var str1 = '8***8***';
var str2 = '898-8293';

var result = [];

var arr1 = str1.split('');
var arr2 = str2.split('');

for (var i = 0; i &lt; arr2.length; i++) {
    if (arr1[i] == arr2[i]) {
     result.push('&lt;b&gt;' + arr2[i] + '&lt;/b&gt;');
    }
    else {
     result.push(arr2[i]);
    }
}

var newStr = result.join('');
&lt;/script&gt;
</code></pre>
