Why doesn't this simple javascript statement work to check if the variable exists?
<p>I'm processing some return JSON data.</p>

<p>Sometimes the JSON will return something I can access via</p>

<pre><code> var new_insert_id = data['internal']['new_insert_id'];
</code></pre>

<p>But sometimes this part of the json array data will not be returned at all, and so I need to skip this variable being set.</p>

<p>So I've written a simple check to make sure this data exists before trying to set the variable:</p>

<pre><code> if(typeof data['internal']['new_insert_id'] != 'undefined')
 {
     // if data['internal']['new_insert_id'] is defined, then..
     var new_insert_id = data['internal']['new_insert_id'];
 }
</code></pre>

<p>But when the JSON returns and there is no new_insert_id I am getting the following error:</p>

<pre><code>Uncaught TypeError: Cannot read property 'new_insert_id' of undefined 
</code></pre>

<p>And the line of code it points to as the culprit is the line of my <em>if</em> statement.</p>

<p>What am I missing? I thought my if statement would check if it exists or not, or do I need to do something else when working with arrays?</p>
