Skip to content

Instantly share code, notes, and snippets.

@defvol
Created January 26, 2017 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save defvol/fc2d56f250b8cadb2988bf03afb2985c to your computer and use it in GitHub Desktop.
Save defvol/fc2d56f250b8cadb2988bf03afb2985c to your computer and use it in GitHub Desktop.
Traverse object's properties to build an HTML table
function toTable (obj) {
var td = function (s) { return '<td>' + s + '</td> ' };
var tr = function (s) { return '<tr>' + s + '</tr> ' };
var table = ''
for (var k in obj) table += tr(td(k) + td(obj[k]));
return '<table>' + table + '</table>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment