I've got a standard table here - 6 columns, multiple rows, all filled with data. Right now, my goal is to collect all this table data into an array:
tableData(0) = "1, Hans, Testperson, Munich, Germany"
tableData(1) = "2, Petra, Testperson, Hamburg, Germany"
The idea is that the array index indicates the row the data came from, while the values on the right side represent the column values all wrapped up in a string and separated by ,
.
As of now, my method looks like this:
function getTableData() {
var tableRows = document.querySelectorAll("#tableId tr");
var data = []
for (var j = 1; j < tableRows.length; j++) {
var rowColumns = tableRows [j].querySelectorAll("td")
var columnData = ""
for (var k = 1; k < rowColumns.length; k++) {
columnData = columnData + rowColumns[k].innerText
if (k < rowColumns.length-1) {columnData = columnData + ","}
}
data.push(columnData)
}
}
It's doing the job well, but when the table exceeds 1000 rows, it starts to slow down. Is there a more efficient way to achieve this using only pure JS?
Thank you in advance