Check out example codes for "Javascript convert html entity to string". It will help you in understanding the concepts better.

Code Example 1

const htmlEntities = {
    "&": "&",
    "<": "&lt;",
    ">": "&gt;",
    '"': "&quot;",
    "'": "&apos;"
  };
return str.replace(/([&<>\"'])/g, match => htmlEntities[match]);
}

Learn ReactJs, React Native from akashmittal.com