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, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}

Learn ReactJs, React Native from akashmittal.com