How to check if table cell data has a link, avoiding TypeError: Cannot read properties of null (reading ‘href’) using JS?

I’m trying to get the data from an HTML table, but it keeps giving me this error TypeError: Cannot read properties of null (reading 'href') when one of the rows in col 5 doesn’t come with a link.

I’ve tried both c.getAttribute('href') and c.querySelector('a').href but I get the same error.

function updateAllTasks() {
  var table = document.getElementById("dtable");
  var [, ...tr] = table.querySelectorAll("tr");
  var tableData = [...tr].map(r => {
  var td = r.querySelectorAll("td");
  return [...td].map((c, j) => j == 3 ? c.innerHTML.toString() : j == 4 && c.innerHTML != '' ?  c.getAttribute('href') : j == 8 ? c.querySelectorAll('input[name="rowcheckbox"]')[0].checked : c.innerHTML);
  })
  const finalDataset = tableData.map(e => [e[0], e[1], e[8]]);
  google.script.run.updateAllClientsTasks(finalDataset);
}

Thank you!