I've created an application for converting a table to JSON object, the application is working fine but the problem is that an empty array is first appearing for the body key. can anyone tell me some
{"head":["Person Name","Person Name","Points","Price","Tax"],"body":[[],["Jill","Smith","50","150","41"],["Eve","Jackson","94","250","81"],["John","Doe","80","950","412"],["Adam","Johnson","67","750","941"]]}
my script is given below
$('#convert-table').click( function() {
try{
var myTable = [];
var myTr =[];
$('#example-table tr').each(function (i, tr) {
var myTd =[];
$('th', tr).each(function(j, th) {
myTr.push($.trim(th.innerHTML));
});
$('td', tr).each(function(j, td) {
if(td.innerHTML.indexOf("span") != -1){
var text = $(this).closest('td').find('span').text();
myTd.push($.trim(text));
}
else{
myTd.push($.trim(td.innerHTML));
}
});
myTable.push(myTd);
});
var headObj ={
head:myTr,
body:myTable
};