print_r in Javascript
It’s a real headache when you have to work on objects and arrays in Javascript. It would be lot easier to detect elements of the Javascript objects/arrays if we have print_r function in Javascript as we have in PHP.
I googled the web and have found a very efficient print_r Javascript function. This has helped me a lot in my projects. Here is the code:-
<script type="text/javascript">
function print_r(theObj){
if(theObj.constructor == Array || theObj.constructor == Object){
document.write("<ul>")
for(var p in theObj){
if(theObj[p].constructor == Array || theObj[p].constructor == Object){
document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
document.write("<ul>")
print_r(theObj[p]);
document.write("</ul>")
} else {
document.write("<li>["+p+"] => "+theObj[p]+"</li>");
}
}
document.write("</ul>")
}
}
</script>
USING PRINT_R
<script type="text/javascript"> print_r(JAVACRIPT_ARRAY_OR_OBJECT); </script>
Source: http://www.brandnewbox.co.uk/articles/details/a_print_r_equivalent_for_javascript/
From Mukesh Chapagain's Blog, post print_r in Javascript
Related posts:
- Javascript: Show/Hide HTML elements
- Website statistic (User Information) in Javascript
- Javascript: Add Remove HTML elements
- Javascript: How to Submit form and Change form action?
- PHP Javascript : Playing with multi-dimensional array
- jQuery: Print array and object
- jQuery: Grey out background and preview image as popup
- Javascript: How to get current URL without Query string?
- Go back link in Javascript
- Javascript: Show Hide textbox text on focus
