Is there an equivalent for var_dump (PHP) in Javascript?


We need to see what methods/fields an object has in Javascript.

11/27/2008 11:29:30 AM

Accepted Answer

As the others said, you can use Firebug, and that will sort you out no worries on Firefox. Chrome & Safari both have a built-in developer console which has an almost identical interface to Firebug's console, so your code should be portable across those browsers. For other browsers, there's Firebug Lite.

If Firebug isn't an option for you, then try this simple script:

function dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";


    // or, if you wanted to avoid alerts...

    var pre = document.createElement('pre');
    pre.innerHTML = out;

I'd recommend against alerting each individual property: some objects have a LOT of properties and you'll be there all day clicking "OK", "OK", "OK", "O... dammit that was the property I was looking for".

7/5/2011 6:24:04 PM

If you are using firefox then the firebug plug-in console is an excellent way of examining objects


Alternatively you can loop through the properties (including methods) like this:

for (property in object) {
    // do what you want with property, object[property].value

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