html-table-to-array
v1.0.0
Published
Turns an HTML table -- with or without headers -- into an array of arrays.
Downloads
2
Readme
The full code for this package:
module.exports = function HTMLTableToArray (element, withHeader /* defaults to false */) {
element = typeof element === 'string' ? document.querySelector(element) : element
var a = []
var rows = element.querySelectorAll('tr')
for (var i = 0; i < rows.length; i++) {
var row = rows[i]
var aa = []
var cells = row.querySelectorAll(withHeader ? 'th,td' : 'td')
for (var j = 0; j < cells.length; j++) {
var cell = cells[j]
aa.push(cell.innerText)
}
if (!withHeader) {
// ignore header rows
if (row.querySelectorAll('th').length > 1) continue
}
a.push(aa)
}
return a
}