Wednesday, November 14, 2012

Examine contents of a JavaScript Object

Here is a bit of a code to peek into the contents of a JavaScript object:

1:  for( key in inst ) {  
2:        console.log( "key is " , [ key ] , ", value is " , inst[ key ] );  
3:        if ((key == "input")||(key == "dpDiv")||(key =="settings")||(key == "trigger" )){  
4:             var subObj = inst[key];  
5:             for (key1 in subObj) {  
6:                  console.log( "key1 is ", [ key1 ] , ", value is " , subObj[ key1 ] );  
7:             }  
8:        }  
9:  }  
The above writes out the object state to the browser's console. Note the comma separation in the log() call.