Skip to content

Instantly share code, notes, and snippets.

@jasp402
Created March 14, 2019 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasp402/a3b5f3d33b7b9e654174b04cd11ea0ab to your computer and use it in GitHub Desktop.
Save jasp402/a3b5f3d33b7b9e654174b04cd11ea0ab to your computer and use it in GitHub Desktop.
JavaScript - Get text of table to convert in Object
var tblhdr = $('#folder_list_218 th').map(function () {
return $(this).text();
}).get();
console.log(tblhdr);
var tbl = $('#folder_list_218 tbody tr').map(function(idx, el) {
var td = $(el).find('td');
var obj = {id: idx+1};
for (var i = 0; i < tblhdr.length; i++) {
obj[tblhdr[i]] = td.eq(i).text();
}
return obj;
}).get();
console.log(tbl);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment