Skip to content

Instantly share code, notes, and snippets.

@SimonJThompson
Last active August 29, 2015 14:14
Show Gist options
  • Save SimonJThompson/8ce3b79a99c1e3b10b73 to your computer and use it in GitHub Desktop.
Save SimonJThompson/8ce3b79a99c1e3b10b73 to your computer and use it in GitHub Desktop.
JS object arrays to table
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