Last active
August 29, 2015 14:14
-
-
Save SimonJThompson/8ce3b79a99c1e3b10b73 to your computer and use it in GitHub Desktop.
JS object arrays to 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
function tableFromObjectArray(arr) { | |
var tStr = "<table>"; | |
tStr+="<thead><tr>"; | |
for(prop in arr[0]) { | |
tStr+="<td>"+prop+"</td>"; | |
} | |
tStr+="</tr></thead>"; | |
for(var i=0;i<arr.length;i++) { | |
tStr+="<tr>"; | |
for(prop in arr[i]) { | |
tStr+="<td>"; | |
tStr+=arr[i][prop]; | |
tStr+="</td>"; | |
} | |
tStr+="</tr>"; | |
} | |
tStr+="</table>"; | |
return tStr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment