Javascript: Write Console.debug() output to browser?
javascript, json, loops
Solution
Yes, you can process a surprising amount of info through alert, and you can also use it for debugging.
Here is a print_r equivalent for javascript also.
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>")
}
}
good luck with your project!
Problem
I need to be able to take any JSON data and print the key/value pairs. (something similar to print_r() in PHP) Is this even possible with javascript?