jQuery: print_r() display equivalent?


Possible Duplicate:
JavaScript data formatting/pretty printer

I am getting a bit tired of looking at unformatted json blobs in FireBug.

Does anyone know an equivalent to PHP's print_r() for jQuery?

Something that would recursively make a display string from an object or array, that I could display on the page for quick debugging?


5/23/2017 12:10:54 PM

Accepted Answer

console.log is what I most often use when debugging.

I was able to find this jQuery extension though.

10/10/2012 1:12:33 PM

You could use very easily reflection to list all properties, methods and values.

For Gecko based browsers you can use the .toSource() method:

var data = new Object();
data["firstname"] = "John";
data["lastname"] = "Smith";
data["age"] = 21;

alert(data.toSource()); //Will return "({firstname:"John", lastname:"Smith", age:21})"

But since you use Firebug, why not just use console.log?

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow