I try to create js obj form a table. like following and I want a json object form it using jquery.
First row tr should be consider as header and rest of tr as body. The order should be as row index of table tr.
<table class='table-out'>
<tr class='header'>
<td>title</td>
<td>name</td>
<td>address</td>
</tr>
<tr>
<td>Mr.</td>
<td>John Doe</td>
<td>St. Michael Rd.</td>
</tr>
<tr>
<td>Mr.</td>
<td>Daniel Kautman</td>
<td>St. Michael Rd.</td>
</tr>
</table>
JSON Obj I need:
tableObj =
[
head:
{
txttitle: title,
txtName: Name,
txtAddrs: Address,
order: 1
}
body:
[{
txttitle: Mr,
txtName: John Doe,
txtAddrs: St. Michael Rd
order: 1
},
{
txttitle: Mr,
txtName: Mrak Doe,
txtAddrs: 3 Z, Moyed Park
order: 2
},
{
txttitle: Mr,
txtName: Meghan Slattery,
txtAddrs: address here
order: 3
}]
]
Something i try like-
$('.table-out>tbody>tr').each(function (index, elem){
if($(this).hasClass(header)){
......
}else{
......
}
});