Check out example codes for "javascript escape html". It will help you in understanding the concepts better.
Code Example 1
function escapeHtml(str) {
return str.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
Learn ReactJs, React Native from akashmittal.com