error code
const exp = JSON.parse('<%= JSON.stringify(cafe.reviews || []) %>');
& # 3 9 ; causing issue. ans tried every thing around the internet but still having same error..
code:
<script>
const exp = JSON.parse('<%= JSON.stringify(cafe.reviews || []) %>');
function escapeHTML(str) {
return str.replace(/[&<>"']/g, match => ({
'&': '&',
'<': '<',
'>': '>',
'"': '"',
"'": '''
}[match]));
}
const experience = document.querySelector('.usersExperience');
if (experience) {
experience.innerHTML = exp.map(review => `
<div>
<h4>${escapeHTML(review.userId?.name || "N/A")}</h4>
<h3>${escapeHTML(review.userId?.dietaryIdentity || "N/A")}</h3>
<p>${escapeHTML(review.review || "N/A")}</p>
</div>
`).join("");
}
</script>
guys. What am i doing wrong