Saturday, March 15, 2008

iterate through javascript object

function show(value)
{
var count = 0
document.write(showObj(value));

function showObj(o)
{
count++;
var ret = ""
for(var x in o)
{
if (typeof o[x] == "object")
{
for (var i = 0; i < count; i++)
{
ret += "-------";
}
ret += x + ": " + "
" + showObj(o[x]) + "
";
}
else
{
for (var i = 0; i < count; i++)
{
ret += "-------";
}
ret += x + ": " + o[x] + "
";
}
}
count--;
return ret;
}
}

1 comment:

Anonymous said...

nice post. I would love to follow you on twitter.