Reputation: 39017
I have opened the Javascript Debugger (Ctrl+Shift+L) in Chrome and started using it to set breakpoints in my code.
This is a much different interface compared to Firebug, (it's all command line driven) so I'm wondering how to do a simple thing like print 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 I only seem to get a single property back, and I'm not sure which property will appear:
$ print opts
#<an Object>
Trying to get all the properties:
$ print for(var p in opts) p;
prop1
Any ideas? It obviously has more than just one...
Upvotes: 4
Views: 5271
Reputation: 1026
You can just type the object name into the Chrome debugger command line and get a browsable listing. In my case I wanted all the properties and methods that I could cut/paste to 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...
Upvotes: 1
Reputation: 39017
So I've tried using the "dir" command, and it gives me something at least:
$dir opts
3 properties
prop1: string (#11#)
prop2: string (#12#)
prop3: string (#13#)
This also works (slightly better because it gives me some values), but cuts off the end of the string if it's 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]
Upvotes: 1
Reputation: 62583
Chrome has ECMA-style native JSON, so you can use
JSON.stringify (opts);
{"prop1":"<some><string/></some>","prop2":2,"prop3":[1,2,3]}
Upvotes: 6
Reputation: 16455
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 to it.
Upvotes: 0