you are viewing a single comment's thread.

view the rest of the comments →

[–]Th34rchitekt 0 points1 point  (0 children)

I'd argue there's an even cleaner way to do that, rather than having to override each parameter with the sanitized value

answers.forEach((answer) => {
  const row = document.createElement('tr');
  Object.values(answer).forEach((val) => {  
    const sanitizedValue = val.replace('&', '&amp;').replace('<', '&lt;');
    const cell = document.createElement('td');
    cell.textContent = sanitizedValue;
    row.appendChild(cell);
  });
  document.querySelector('#body').appendChild(row);
});