HTML:
<p>Load these table values into an array</p>
<table>
<tr>
<th>Number</th>
<th>Count</th>
</tr>
<tr>
<td>1</td>
<td>10</td>
</tr>
<tr>
<td>2</td>
<td>80</td>
</tr>
<tr>
<td>3</td>
<td>25</td>
</tr>
<tr>
<td>4</td>
<td>30</td>
</tr>
<tr>
<td>5</td>
<td>45</td>
</tr>
<tr>
<td>6</td>
<td>35</td>
</tr>
<tr>
<td>7</td>
<td>12</td>
</tr>
<tr>
<td>8</td>
<td>10</td>
</tr>
<tr>
<td>9</td>
<td>21</td>
</tr>
</table>
<p>Output array values to this table</p>
<table class="myTable">
<tr>
<th width="10%">Number</th>
<th width="10%">Count</th>
</tr>
</table>
JS:
var i = 0;
var values = Array();
$("table tr td").each(function(i, v) {
values[i] = $(this).text();
})
tablegenerate(values);
function tablegenerate(values) {
for (i = 0; i < values.length;) {
var $formrow = '<tr><td>' + values[i] + '</td><td>' + values[i + 1] + '</td><tr>';
i = i + 2;
$('.myTable').append($formrow);
}
}
Loosely based on Convert Table to an Array. This loads the 2-column table values into one array and then outputs the data to another 2-column table, but rather than loading both columns of data in to one array and then outputting every other array value for the 2nd column like I am currently doing, I want to load and output the two columns of data separately. How can I process the two (or more) columns of data separately (2 arrays)?