Advertisement
guitarplayer616

JS tableToJson

Jul 21st, 2021
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function tableToJson(table) {
  2.     var data = [];
  3.     for (var i=0; i<table.rows.length; i++) {
  4.         var tableRow = table.rows[i];
  5.         var rowData = [];
  6.         for (var j=0; j<tableRow.cells.length; j++) {
  7.             rowData.push(tableRow.cells[j].innerText);;
  8.         }
  9.         data.push(rowData);
  10.     }
  11.     return data;
  12. }
  13.  
  14. var table = document.querySelector("tbody")
  15. var json = tableToJson(table)
  16. console.log(JSON.stringify(json))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement