Dump javascript objects recursively
A bit ugly, but only for testing purpose.
by leeroy
JavaScript
function dump(obj, indent, display) {
if(indent == undefined) indent = '';
if(display == undefined) display = true;
var out = '';
for (var i in obj) {
out += indent + i + ": " + obj[i] + "\n";
if(typeof obj[i] == 'object') out += dump(obj[i], indent+' ', false);
}
if(display === true)
document.write('<pre>'+ out +'</pre>');
else
return out;
}
dump({hello: 'world', world: 'hello', subobject: {test: 'test1 val', test2: 'test2 val', subsubobject: {subsub1: 'test1', subsub2: 'test2'}}, helloworld: 'hello world'});