I'm looking for a way to get the (first,second, third so on) td values, and store them in array.
Using each
to iterate a td:
$("table tbody tr td").each(function(i,e){
console.log($(this).html());
});
With this code I need to to take all columns values, e.g.:
George
Princeton
Alabama
Pizza
How to store these values in array with the respective keys: Name, College, State, Food
. I was thinking this:
var array = [];
$("table tbody tr td").each(function(i,e){
array['Name'] = $(this) ?? //I dont know how get the first td.
});
I don't know if it is the best way to iterate a table, but a think that I'm missing something in how to get the first, second, third td values.
Table: (This is just an example, the values are dynamically created)
<table >
<tbody>
<tr>
<td> George </td>
<td> Princeton </td>
<td> Alabama </td>
<td> Pizza </td>
</tr>
<tr>
<td> Charli</td>
<td> Princeton </td>
<td> Alabama </td>
<td> Milk Shake </td>
</tr>
<tr>
<td> Max</td>
<td> Princeton </td>
<td> Alabama </td>
<td> Rice </td>
</tr>
<tr>
<td> Peter</td>
<td> Princeton </td>
<td> Alabama </td>
<td> Fast Food </td>
</tr>
</tbody>
</table>