title: Want to use IF statement with JSON
body: <p>I have very simple code taking items from a <strong>JSON</strong> file and displaying them in a <strong>DIV</strong>. However, currently I am accessing each item based on its order in the array. I want to add an IF statement in addition to each item incase the order gets changed in the <strong>JSON</strong> file. Each item has its own id as well. For example, <code>data[0].itemName</code> could end up becoming <code>data[1].itemName</code> if the <strong>JSON</strong> file is altered. </p>
  
  <pre><code>(function() {
  
   'use strict';
  
   var url = 'path to json';
  
   $.getJSON(url, function(data) {
  
              $('#recipeIngredients').html(
  
              "&lt;ul&gt;" + 
                  "&lt;li&gt;" + '1/2 tsp salt' + "&lt;/li&gt;" +
                  "&lt;li&gt;" + '2 cups ' + (data._id == "1" ? data.itemName : " ") + "&lt;/li&gt;" +
                  "&lt;li&gt;" + data.itemName + "&lt;/li&gt;" +
              "&lt;/ul&gt;");
  
   });
  </code></pre>
  
  <p>})();</p>
  
  <p><strong>JSON</strong> is as follows:</p>
  
  <pre><code>var data = [ { "itemName" : "exampleItem1", "_id" : "1" }, { "itemName" : "exampleItem2", "_id" : "2" } ]
  </code></pre>