Friday, October 30, 2009

Printing Javascript object properties

If you would like to print out all the properties of an Javascript object and their associated values, do this:

Note: Replace < objName > below with the name of your instantiated object.

var str;

for(prop in < objName >)
str += prop + ' value :' + < objName >[prop]+ '\n ';

alert(str); //Show all properties and its value

No comments:

Post a Comment

Thank you for your comment.