Possible Duplicate:
Checking existence of properties in JavaScript
I am trying to get the first row of a table’s tbody cells (i.e. this.tBodies[0].rows[0].cells) without using jQuery. If there are not any, I do not wish to cause an error.
The following seems to work, but is there a better way?
var tbody_cells = (this.tBodies
&& this.tBodies
&& this.tBodies[0].rows
&& this.tBodies[0].rows[0])
? this.tBodies[0].rows[0].cells
:undefined;
Use a try catch block: