Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- const checkBoxes = document.querySelectorAll('thead th input[type="checkbox"]');
- const rows = document.querySelectorAll('tbody tr');
- const headings = document.querySelectorAll('thead th');
- let checkedIndexes = [];
- for (let i = 0; i < checkBoxes.length; i++) {
- if (checkBoxes[i].checked) {
- checkedIndexes.push(i);
- }
- }
- let result = [];
- for (let row of rows) {
- const cells = row.querySelectorAll('td');
- let rowObject = {};
- for (let j = 0; j < checkedIndexes.length; j++) {
- const index = checkedIndexes[j];
- const headingCell = headings[index];
- const headingName = headingCell.childNodes[0].textContent.trim();
- rowObject[headingName] = cells[index].textContent.trim();
- }
- result.push((rowObject));
- }
- document.getElementById('output').value = JSON.stringify(result);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement