title: JavaScript: How to Loop through JSON objects with jQuery in an AJAX call
body: <p>I am having difficulty trying to learn this concept. </p>
  
  <p>I have a JSON file with a list of hospitals, their address, hours and phone.</p>
  
  <p>I want to make an AJAX call from JSON data and list the data onto the screen. </p>
  
  <p>I can only get the first hospital to list, when I try to list the address only the address lists.</p>
  
  <p>How can I write this using a loop that will list the objects and their properties?</p>
  
  <p>Can someone explain this to me, please?</p>
  
  <p>Please help -- thank you in advance.</p>
  
  <p>JSON --</p>
  
  <p><a href="https://api.myjson.com/bins/b29r7" rel="nofollow noreferrer">https://api.myjson.com/bins/b29r7</a></p>
  
  <p>JS --</p>
  
  <pre><code>var url = 'https://api.myjson.com/bins/b29r7';
  
  $.ajax({
      url: url,
      method: 'GET',
  }).done(function(result){
      var data = result.surrey;
      for(var i=0; i&lt;data.length; i++){
          $('#data').each(function(index, ele){
              $(ele).html(data[index].hospital);
          });
      }
  }).fail(function(err){
      throw err;
  });
  </code></pre>
  
  <p>HTML --</p>
  
  <pre><code>&lt;p id="data"&gt;&lt;/p&gt;
  </code></pre>