I could not find the answer that processed the circulars, and I also decided to do it without any unnecessary DOM entries. In addition, I did not follow the exact markup requested by the OP because I felt that the nesting tables were more convenient for a recursive operation such as this and served almost the same visual purpose.
So here is the function created:
function dataToTable (data) { var storage = []; return (function buildTable (data) { var table = '<table><tbody>'; var name, value;
Here is the object I used for testing:
var obj = { a : { x : 1, y : 2, z : 3 }, b : { x : 1, y : 2, z : { test1: 0, test2: { test3: 1, test4: ['a','b','c'] } } } }; obj.c = obj; obj.bztest2.test4.push(obj.a);
The function will turn this object into an HTML table. What you do with the table is up to you. On my fiddle, I used the DOM to add a table to the DIV (document.getElementById).
http://jsfiddle.net/5RhXF/1/
I hope you find that my implementation is clear.
UPDATE ::
I decided to check this out in the jQuery library and it worked! In addition, functions were printed as their toString value without a good text format. It makes sense, but not very useful. So, I think this is a good and easy way to look at the APIs for frameworks / libraries and what not. Therefore, I added prettify to highlight the syntax of functions, and also added type checking for functions in the table generator and a quick class to get rid of the borders around the prettify field (since there is already a border on the table cell), If someone is interested in the version, for reading / debugging the source, here is the fiddle:
http://jsfiddle.net/5RhXF/7/