var params = {
"fruit":"apple",
"test": "Nope",
"values": [
],
}
$(function(){
$('button').click(function() {
$("#mytable tr").each(function(index, item){
var temp = []
if(index == 0) {
$(item).find('th').each(function(idx, col){
temp.push($(col).text());
})
}
$(item).find('td').each(function(idx, col){
temp.push($(col).text());
})
params.values.push(temp)
})
console.log(params);
})
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="mytable">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
</table>
<button>Click</button>
Post a Comment for "Put Table In Array"