I have two strings:
var str1 = '8***8***';
var str2 = '898-8293';
How can i wrap the digits found in string one, with html elements on the second string, like so:
'<b>8</b>98-<b>8</b>293'
Note: Not all '8' digits are wrapped.
[EDIT]
Thanks to Soufiane Hassou and voyager the following worked:
<script type="text/javascript">
var str1 = '8***8***';
var str2 = '898-8293';
var result = [];
var arr1 = str1.split('');
var arr2 = str2.split('');
for (var i = 0; i < arr2.length; i++) {
if (arr1[i] == arr2[i]) {
result.push('<b>' + arr2[i] + '</b>');
}
else {
result.push(arr2[i]);
}
}
var newStr = result.join('');
</script>