Advertisement
Kamend1

08. Generate report

Mar 20th, 2025
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.     const checkBoxes = document.querySelectorAll('thead th input[type="checkbox"]');
  3.     const rows = document.querySelectorAll('tbody tr');
  4.     const headings = document.querySelectorAll('thead th');
  5.  
  6.     let checkedIndexes = [];
  7.  
  8.     for (let i = 0; i < checkBoxes.length; i++) {
  9.         if (checkBoxes[i].checked) {
  10.             checkedIndexes.push(i);
  11.         }
  12.     }
  13.  
  14.     let result = [];
  15.  
  16.     for (let row of rows) {
  17.         const cells = row.querySelectorAll('td');
  18.         let rowObject = {};
  19.        
  20.         for (let j = 0; j < checkedIndexes.length; j++) {
  21.             const index = checkedIndexes[j];
  22.             const headingCell = headings[index];
  23.             const headingName = headingCell.childNodes[0].textContent.trim();
  24.             rowObject[headingName] = cells[index].textContent.trim();
  25.         }
  26.         result.push((rowObject));
  27.     }
  28.  
  29.     document.getElementById('output').value = JSON.stringify(result);
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement