Search code examples
extjsloggingextjs4.2

Print a custom object on console in extjs


I am trying my hands on extjs 4.2.2 on a UI development. I am totally new to this. I am unable to understand how to print the objects for which i dont know the properties. Can someone please help me out in this.

If i know the property of the object i can do it as below.

console.log('print: ' + myObj.get('name'));

But if i dont know the property(in this case name) how can get to print it? Is there any way of iterating the object properties and print it. Kindly help me on this.


Solution

  • Yes, you can iterate through properties of an object using for .. in loop

    for (var prop in obj) {
        console.log("o." + prop + " = " + obj[prop]);
    }
    

    Another way would be to encode the object to string:

    console.log(Ext.encode(o))
    

    However, I usually log the complete object console.log(o) and the I use the console UI to browse through properties of interest.