title: Jquery JSON - Detect if a certain key exists
body: <pre><code>if(data.hasOwnProperty('date'){
       var start = data.date
  }else{
      var start = data.datetime
  }
  </code></pre>
  
  <p>This is an example of the code I'm trying to use - Though it fails to work, always returning only of the two options. Other things I have tried is using if(data.key), typeof...</p>
  
  <p>So to provide more information about the issue - I'm trying to fetch data from a google api server. The data fetches correctly in the fact that I can display data fetched from the server clearly. The issue lies in the fact that my client uses two different formats for receiving start and end date. Date which is a YYYY-MM-DD format, and DateTime which also provides a hour. The api deals with showing the correct one by only showing that key. Meaning it either shows a date or a datetime key, never both. Hence I'm trying to detect if one of the keys exists, but calling upon them seems to return "undefined" and I'm drawing a blank on how to make it work.</p>
  
  <p>An example of the JSON returned by the api:</p>
  
  <pre><code>"start": {"date": "2015-03-20"}
  </code></pre>
  
  <p>In some cases the date key will instead be datetime, and provide the other format.</p>
  
  <p>Hence my question is, how does one make sure that only the correct key is called upon, if the other key returns undefined?</p>
  
  <p>I'm using Jquery + Jquery mobile. Any help is appreciated.</p>