title: Javascript forEach not working
body: <p>My goal is to iterate through an array of results and do stuff with the data but for some reason I can't get the foreach loop in javascript to work, I can't seem to make any sort of enumeration work.</p>
  
  <p>Here's my test</p>
  
  <pre><code>console.debug("I got this far.");
  for(var i=0;i&lt; results.length; i++){
      console.debug("Worked.");
  }
  console.debug("Past.");
  console.debug(results);
  </code></pre>
  
  <p>I have also tried</p>
  
  <pre><code>results.forEach(function(x) { console.debug("Worked"); });
  </code></pre>
  
  <p>and</p>
  
  <pre><code>for(var x in results)
  </code></pre>
  
  <p>None seem to be working, is there something I'm doing wrong?</p>
  
  <p>The output for the above is </p>
  
  <pre><code>I got this far.  query.html:39
  Past.            query.html:40
  [ Object , Object , Object , Object , Object , Object , Object , Object , Object , Object ]
  </code></pre>
  
  <p>So I know that the results variable is the right type but it is just not iterating.  There is another place where the forEach() works just fine but here it's not, any suggestions on how to debug and address this would be helpful.</p>
  
  <p>full code (WORKING SOLUTION)</p>
  
  <pre><code>var table;
  var request = { query : { match_all : {}}};
  var map;
  function initialize(results) {
      var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(41.4, -71.3),
        mapTypeId: google.maps.MapTypeId.ROADMAP
      };
      map = new google.maps.Map(document.getElementById('map_canvas'),
          myOptions);
      results.forEach(function(x) {
        var markerLoc = new google.maps.LatLng(x.location.lat, x.location.lon);
        var marker = new google.maps.Marker({
          position: markerLoc,
          map: map,
          title: "Hello World!"
          });
        });
  
  };
  $(document).ready(function() {
          var results = [];
          $.ajax({
              url: "http://localhost:9200/devices/devices/_search",
              type: "POST",
              data: JSON.stringify(request),
              dataType: "json",
              beforeSend: function(x) {
                  if ( x &amp;&amp; x.overrideMimeType) {
                      x.overrideMimeType("application/j-son;charset=UTF-8");
  
                      }
              },
              success: function(data) { 
                  data.hits.hits.forEach(function(x) { results.push(x._source); } );
                  initialize(results);
              }
  
          });
  
  });
  </code></pre>