views:

659

answers:

3

I have an object I need to examine in IE8. I tried the developer tools and console.log, their Firebug equivalent. However, when I output the object to the log:

console.log("Element: ", element);
console.log(element);

I only get the string

LOG: Element: [object Object]

instead of a clickable, examinable dump.

Is it possible to dump an object to the Log and examine its members, like in Firebug?

I can't use a homemade dump() function because the element I want to examine is so huge the browser will crash on me.

A: 

console.log(element.toString()) might be your friend here...

RyanWilcox
Good idea, but sadly, same output...
Pekka
nope this shouldnt definitely work
I__
I don't think this deserves a downvote - it works perfectly fine, just not the way I need. Downvotes should be reserved for blatantly *wrong* answers. +1 to even it out.
Pekka
the .toString() is what the interpreter calls when you try to output an object. So basically console.log(element) is the same as console.log(element.tostring())
naivists
+4  A: 

Here's one technique that I've found helpful:

  • Open the Developer Tool Bar (hit F12)
  • Go to the "Script" tab
  • Click the "Start Debugging" button
  • Next, type "debugger" into the console and hit enter. This should trigger a break point.
  • Go to the "Watch" sub-tab
  • Click the row that says, "Click to add..." and enter a variable you'd like to examine. Note that the variable must be globally available.
  • At this point you should be able to examine your variable with tree-like UI
  • Once you're done debugging click Continue button (or hit F5)

Here's a screen shot that highlights some of the UI elements I mentioned: IE8 Developer Toolbar

Xavi
I don't have the time to go into this right now, but I'm pretty sure it's going to help me. Thanks for the step by step directions.
Pekka
+2  A: 

A bit off topic (as it won't work for DOM elements) but I've found it handy to use the JSON.stringify(object) to get a JSON string for the object which is pretty readable.

Andy