JSFiddle - React, Tailwind, and code Playground
by borsna
HTML
<table id="myTable">
<thead>
<tr>
<th>svenska</th>
<th>engelska</th>
</tr>
</thead>
<tbody>
<tr>
<td>apa</td>
<td>monkey</td>
</tr>
<tr>
<td>lök</td>
<td>onion</td>
</tr>
</tbody>
</table>
JavaScript
var words = getTableValues("myTable");
console.log(words);
console.log(words[1].svenska);
function getTableValues(id){
var head = new Array();
$("#"+id+" thead th").each(function(th){
head.push($(this).html());
});
var values = new Array();
$("#"+id+" tbody tr").each(function(tr){
var row = Array();
var index = 0;
$(this).children("td").each(function(td){
row[head[index]] = $(this).html();
index++;
});
values.push(row);
});
return values;
}