CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 06/23/2008 in javascript


There are many versions of this file floating around - but I had to whip one together I use in almost all my development and unit/regression testing facilities. This will output a clean hierarchical div-based display of any object - at least within the browser's recursive traversal limitations.

And here's an example javascript object:
print_r([{function:'testing',arguments:['arg1','arg2']}])
And the output HTML:

[0] => object
[function] => testing
[arguments] => object
[0] => arg1
[1] => arg2


Here's the function:
function print_r(theObj) {
	var retStr = '';
	if (typeof theObj == 'object') {
		retStr += '<div style="font-family:Tahoma; font-size:7pt;">';
		for (var p in theObj) {
			if (typeof theObj[p] == 'object') {
				retStr += '<div><b>['+p+'] => ' + typeof(theObj) + '</b></div>';
				retStr += '<div style="padding-left:25px;">' + print_r(theObj[p]) + '</div>';
			} else {
				retStr += '<div>['+p+'] => <b>' + theObj[p] + '</b></div>';
			}
		}
		retStr += '</div>';
	}
	return retStr;
}
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar