JavaScript convertit l'entité html en chaîne

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