Logo
doctype [?]
[strict] [loose] [none]

Data Dumper


Perl has a great module called Data::Dumper that will show you an object's structure easily and quickly. I often found myself wanting to see similar output in Javascript, so I built a DataDumper library which gives similar type of output. If you're building complex data structures or objects, this lirary can help you debug your code and see exactly what data is where!

Example

Given this object structure:

<script type="text/javascript">
var obj = new Object();
obj["stringValue"] = "mystring";
obj["numberValue"] = 123;
obj["booleanValue"] = false;
obj["nullValue"] = null;
obj["functionValue"] = function dummy() { };
obj["domobject"] = new Option('test','test',false,false);
obj["nestedStructures"] = new Object();
obj['self'] = obj;
obj["nestedStructures"]["subObject"] = new Object();
obj["nestedStructures"]["subObject"]["subArray"] = new Array("one",2,false,new Object(),new Array());
obj["nestedStructures"]["subObject2"] = new Object();
obj["nestedStructures"]["subObject2"]["subArray"] = new Array();
</script>

Running this code:

Dumper.write(obj);

Results in this output:


You can also alert() the output or write it to a popup window.