Created
May 12, 2015 16:01
-
-
Save joeSaad/1599dab00dab70604ac9 to your computer and use it in GitHub Desktop.
Putting a table into an array of objects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
table>thead(>tr>th{column $}*4)+tbody(>tr*5>td{data $}*4) | |
*/ | |
<table> | |
<thead> | |
<tr> | |
<th>column 1</th> | |
<th>column 2</th> | |
<th>column 3</th> | |
<th>column 4</th> | |
</tr> | |
</thead> | |
<tbody> | |
<tr> | |
<td>data 1</td> | |
<td>data 2</td> | |
<td>data 3</td> | |
<td>data 4</td> | |
</tr> | |
<tr> | |
<td>data 1</td> | |
<td>data 2</td> | |
<td>data 3</td> | |
<td>data 4</td> | |
</tr> | |
<tr> | |
<td>data 1</td> | |
<td>data 2</td> | |
<td>data 3</td> | |
<td>data 4</td> | |
</tr> | |
<tr> | |
<td>data 1</td> | |
<td>data 2</td> | |
<td>data 3</td> | |
<td>data 4</td> | |
</tr> | |
<tr> | |
<td>data 1</td> | |
<td>data 2</td> | |
<td>data 3</td> | |
<td>data 4</td> | |
</tr> | |
</tbody> | |
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tArr = []; | |
var tObj = {}; | |
for (var i=0; i< $('tbody tr').length; i++){ | |
for (var j = 0; j< $('th').length; j++){ | |
tObj[$('th').eq(j).text()] = $('tbody tr:eq('+i+') td:eq('+j+')').text(); | |
//console.log(tObj); | |
} | |
tArr.push(tObj); | |
} | |
console.log(tArr); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment