I have a table consisting of multiple rows. Each row contains 5 data cells and the innerHTML of each cell is different:
HTML
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
<td>Data 5</td>
</tr>
<tr>
<td>Data 6</td>
<td>Data 7</td>
<td>Data 8</td>
<td>Data 9</td>
<td>Data 10</td>
</tr>
...
JavaScript
The below code gets the data from the first 5 cells, but I need to loop through all rows and then each cell within each row.
var allTableData = [];
var tableData = $('td');
_.each(tableData, (data, i) => {
if (i < 5) {
allTableData.push(data.innerHTML);
}
});
My desired output is:
values: [
['Data 1', 'Data 2', 'Data 3', 'Data 4', 'Data 5'],
['Data 6', 'Data 7', 'Data 8', 'Data 9', 'Data 10'],
[...]
];
How would I get my desired output with JavaScript/JQuery?
<tr>tags and then a loop inside of that loop loops through all the<td>tags.