简体   繁体   中英

How to map specific HTML table columns and get its data into an array (JS)?

I'm trying to get the table data from some columns and I've tried a couple of variations I could think of, but none worked:

function updateAllTasks() {
var table = document.getElementById("dtable");

var [, ...tr] = table.querySelectorAll("tr");
var tableData = [...tr].map(r => {
var td = r.querySelectorAll("td");
    console.log([...td].map(c => c[0].innerHTML, c[1].innerHTML, c[8].querySelectorAll('input[name="rowcheckbox"]')[0].value)); //This is the one giving me error ReferenceError: c is not defined
})
console.log(JSON.stringify(tableData));
}

Thanks for your help!

As mentioned by Andy , following data structures logic. The best approach for this case will be to call the data inside of an Array , and after that, build the table with the data.

This will provide more flexibility the moment you process the information.

Reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM