Convert HTML entity code script

Sometimes when dealing with API response we get HTML entity tag as well. For eg:

In order to fix this kind of issue we can use a simple javascript snippet.

function convertHTMLEntity(text){ const span = document.createElement('span'); return text .replace(/&[#A-Za-z0-9]+;/gi, (entity,position,text)=> { span.innerHTML = entity; return span.innerText; }); } convertHTMLEntity(text);

Leave a Reply

Your email address will not be published. Required fields are marked *