I was trying to access every second cell of each row in a table, but it doesn't seem to be working and just shows a bunch of undefined variables. Is there any way that I can do this? Any help would be appreciated.
Example table :
| Column A | Column B | Column C |
|---|---|---|
| Data 1A | Data 1B | Data 1C |
| Data 2A | Data 2B | Data 2C |
| Data 3A | Data 3B | Data 3C |
Note : I was trying to access the italic data cell.
let table = document.querySelector("table");
for (let row of table.rows) {
for (let cell of row.cells) {
console.log(cell[1]);
}
}
Output :
Undefined
Expecting output :
<td>Data 1B</td>
<td>Data 2B</td>
<td>Data 3B</td>