Skip to content

Instantly share code, notes, and snippets.

@bobdobbalina
Created January 20, 2021 19:24
Show Gist options
  • Save bobdobbalina/844262d1bd8ae6a2ba7946abd889fe38 to your computer and use it in GitHub Desktop.
Save bobdobbalina/844262d1bd8ae6a2ba7946abd889fe38 to your computer and use it in GitHub Desktop.
Javascript: Unescape HTML tags
const unescapeHTML = str =>
str.replace(
/&|<|>|'|"/g,
tag =>
({
'&': '&',
'&lt;': '<',
'&gt;': '>',
'&#39;': "'",
'&quot;': '"'
}[tag] || tag)
);
data["unescapeHTML"] = unescapeHTML('&lt;a href=&quot;#&quot;&gt;Me &amp; you&lt;/a&gt;'); // <a href="#">Me & you</a>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment