To escape HTMl special characters in JavaScrip, use the replace() method. The following are our special characters −
& < >
Try the following code snippet to achieve this −
function display(unsafe) {
return unsafe
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">")
}