In the Chrome JS debugger, how do I print all the properties of an object?

I opened the Javascript Debugger (Ctrl + Shift + L) in Chrome and started using it to set breakpoints in my code.

This is a great interface compared to Firebug (it all controls the command line), so I'm wondering how to do a simple thing, such as printing all the properties of an object.

If I have an object like this:

var opts = { prop1: "<some><string/></some>", prop2: 2, prop3: [1,2,3] } 

I can set a breakpoint and inspect the object, but it seems to me that I am returning only one property, and I'm not sure which property will appear:

 $ print opts #<an Object> 

Trying to get all properties:

 $ print for(var p in opts) p; prop1 

Any ideas? He obviously has more than one ...

+4
source share
4 answers

So, I tried using the "dir" command, and this gives me something at least:

 $dir opts 3 properties prop1: string (#11#) prop2: string (#12#) prop3: string (#13#) 

This also works (a little better, because it gives me some values), but shortens the end of the line if it is too long:

 $ print var s=[];for(var p in opts) { s.push(p + ":" + opts[p]); } s.join(","); prop1:<some><string/></some>,prop2:2,prop3:[object Object] 
0
source

Chrome has built-in JSON in ECMA style, so you can use

 JSON.stringify (opts); {"prop1":"<some><string/></some>","prop2":2,"prop3":[1,2,3]} 
+6
source

Try using the command line in the JavaScript console at the bottom of the Inspector ( Ctrl+Shift+J ). It has a much more Firebug-like feel.

0
source

You can simply enter the name of the object in the command line of the Chrome debugger and get a list of available for viewing. In my case, I wanted all the properties and methods that I could cut / paste into an external document. This worked for me:

 for (a in opts) console.log(typeof (opts[a]) + ' :: ' + a); 

returns:

 string :: id string :: name number :: selectMode string :: url boolean :: multi object :: selectedRows object :: selectedValues function :: Load function :: _LoadInternal function :: _CreatePostElements ...etc... 
0
source

All Articles