Open this example in the interactive library
Source code
const entities = {
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
};
console.log("<b>safe & sound</b>".replace(/[&<>"']/g, (c) => entities[c]));
Sample output
<b>safe & sound</b>
