petur_stoqnov

Untitled

Jan 27th, 2021
966
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateReport() {
  2.     let checkBoxInput = Array.from(document.querySelectorAll('input'));
  3.     let row = Array.from(document.querySelectorAll('tbody tr'));
  4.  
  5.     let output = [];
  6.     for (let i = 0; i < row.length; i++) {
  7.         let obj = {}
  8.         for (let j = 0; j < checkBoxInput.length; j++) {
  9.             if(checkBoxInput[j].checked === true){
  10.                 let prop = checkBoxInput[j].parentNode.textContent.trim().toLowerCase();
  11.                 obj[prop] = row[i].children[j].textContent.trim();
  12.             }
  13.         }
  14.         if(Object.keys(obj).length > 0){
  15.             output.push(obj)
  16.         }
  17.     }
  18.     document.querySelector('textarea').value = JSON.stringify(output, null, 2);
  19. }
RAW Paste Data