I have an two dimensional array, generated from a html table with jQuery, but some values are empty so ""
is displayed.
How can I remove the empty values?
<table>
<tr>
<th>1A</th>
<th>1B</th>
<th>1C</th>
</tr>
<tr>
<td>2A</td>
<td>2B</td>
<td>2C</td>
</tr>
<tr>
<td></td>
<td>3B</td>
<td>3C</td>
</tr>
<tr>
<td></td>
<td></td>
<td>4C</td>
</tr>
</table>
<script>
var columns = $('tr').first().children().map(function(i) {
return [
$('tr').map(function(){
return $(this).children().eq(i).text()
}).get()
]
}).get();
<script>
I already tried following code:
for( var i = 0; i < columns[0].length; i++){
if ( columns[0][i] === "") {
columns[0].splice(i, 1);
}
}
It worked for some empty values, but not all of them got removed for some reason.