Advertisement
Guest User

Untitled

a guest
Jun 17th, 2021
412
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let headRowArray = Array.from(document.getElementsByTagName('input'));
  3.  
  4.     let bodyRowArray = Array.from(document.querySelectorAll('tbody tr'));
  5.  
  6.     let textArea = document.getElementById('output');
  7.  
  8.     let indices = [];
  9.  
  10.     let employees = [];
  11.  
  12.     for (let i = 0; i < headRowArray.length; i++) {
  13.  
  14.         if (headRowArray[i].checked === true) {
  15.  
  16.             indices.push(i);
  17.  
  18.         }
  19.  
  20.     }
  21.  
  22.     for (let i = 0; i < bodyRowArray.length; i++) {
  23.  
  24.         let eInfo = {};
  25.  
  26.         let tdArray = Array.from(bodyRowArray[i].children);
  27.  
  28.         for (let j = 0; j < indices.length; j++) {
  29.  
  30.             let key = headRowArray[indices[j]].name.toLowerCase();
  31.  
  32.             let value = tdArray[indices[j]].textContent;
  33.  
  34.             eInfo[key] = value;
  35.  
  36.         }
  37.  
  38.         employees.push(eInfo);
  39.  
  40.     }
  41.  
  42.     let str = JSON.stringify(employees);
  43.  
  44.     textArea.textContent = str;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement