Skip to main content
Kinetic Community

Debugging - YAHOO.lang.dump

Sometimes you need to view the contents of an array or hash (javascript object), but the typical alert(myobj) statement isn't too helpful because it just indicates if the object exists or not.
 
Here is what the following alert statement will generate:
 
var myobj = { name: 'Jack', department: 'Product Development' };
alert(myobj);

 

alert.jpg

 

That isn't very helpful.

 
 
The YUI library has a built in function that will dump the contents of complex objects, making it very easy to see the data of virtually any variable or property you have.  Here is what the alert statement will generate after running the object through the YUI dump function:
 
var myobj = { name: 'Jack', department: 'Product Development' };
alert(YAHOO.lang.dump(myobj));

 

dump.jpg

That gives a lot more information, and should help when troubleshooting code problems.