We need to see what methods/fields an object has in Javascript.
+7
A:
If you are using firefox then the firebug plug-in console is an excellent way of examining objects
console.debug(myObject);
Alternatively you can loop through the properties (including methods) like this:
for (property in object) {
// do what you want with property, object[property].value
}
Ken
2008-11-27 11:34:16
+1
A:
If you use Firebug, you can use console.log to output an object and get a hyperlinked, explorable item in the console.
Paul Dixon
2008-11-27 11:39:13
+13
A:
As the others said, you can use Firebug, and that will sort you out no worries on Firefox. 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";
}
alert(out);
// or, if you wanted to avoid alerts...
var pre = document.createElement('pre');
pre.innerHTML = out;
document.body.appendChild(pre)
}
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".
nickf
2008-11-27 13:45:38
I'd recommend against it as well - frankly I'd just use console.debug. But I was pointing out the possibility of looping - it is up to the user what they want to do with each property
Ken
2008-11-27 17:52:29
I've been using firebug for a while now, but wasn't aware of Firebug Lite, thanks for pointing it out.
codefin
2008-11-27 18:23:03
Nice snippet. +1
Atømix
2010-05-07 22:24:16