I have an [object Object]
being passed as an argument through a jQuery function and I want to learn more about it. I don't want to know anything about this specific situation (unless there is no solution) but how to replicate something like php's var_dump()
.
Asked
Active
Viewed 153 times
1

Andrew Jackman
- 13,781
- 7
- 35
- 44
-
possible duplicate of [Is there an equivalent for var_dump (PHP) in Javascript?](http://stackoverflow.com/questions/323517/is-there-an-equivalent-for-var-dump-php-in-javascript) – svick Jul 03 '11 at 15:29
3 Answers
4
You could use console.log(your_object_instance);
and look in the FireBug console in FireFox. This also works with Chrome/Safari developers tools. You will learn everything you need about this object such as properties, methods, ...

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928
-
Also, just a note that Chrome and IE9 also have consoles built-in (not sure about Safari). I know you know this, Darin, I just wanted to put it out there. :) – Jared Farrish Jul 03 '11 at 15:33
3
function odump(object, depth, max){
depth = depth || 0;
max = max || 2;
if (depth > max)
return false;
var indent = "";
for (var i = 0; i < depth; i++)
indent += " ";
var output = "";
for (var key in object){
output += "\n" + indent + key + ": ";
switch (typeof object[key]){
case "object": output += odump(object[key], depth + 1, max); break;
case "function": output += "function"; break;
default: output += object[key]; break;
}
}
return output;
}

Pheonix
- 6,049
- 6
- 30
- 48
2
If you're using Firefox you can use Firebug, or if you're on Safari or Google Chrome you can use their developer tools / console. Then use the console.log()
method to dump information about the object into the console:
console.log(obj);
or
console.log({test: "lalala"});

mauris
- 42,982
- 15
- 99
- 131