consider following function
function myFunction() {
var html = "CR_557!#$&'()*+,-./:;<=>?@[]^_`{|}";
var data = html.substring(0, 14);
var newData = '<span style="background-color:#F2E9B7">' + data + '</span>';
return html.replace(data, newData);
}
console.log(myFunction());
the expected content for var html in the end should be:
"<span style=\"background-color:#F2E9B7\">CR_557!#$&</span>'()*+,-./:;<=>?@[]^_`{|}"
but for some reason i am getting this:
"<span style=\"background-color:#F2E9B7\">CR_557!#CR_557!#$&amp;</span>'()*+,-./:;<=>?@[]^_`{|}"
the characters CR_557!# are getting repeated for some reason not sure why.
&with&amp;...$&has a special meaning when used withString.prototype.replace(): "$&Inserts the matched substring." (Source)