title: JavaScript promise skipped for loop and resolved straight away
body: <p>I was having some problem with javascript asynchronous call. I got a list of addresses, and for each address, I am using geocode to get the latitude and longitude. Then, I proceed to format the marker details and push the marker into a marker array. I have used some promise but it does not seem to work:</p>
  <pre><code>var markersToAdd = [];
  function drawmap(mapData){
      let promise = new Promise((resolve, reject) =&gt; { 
          // getlatlng
          resolve(mapData);
      });
      
      promise.then((markersToAdd) =&gt; {
          //loop
          addMarker(markersToAdd[i]);
      });
  }
  
  function getLatLng(address, branchName, total){
      geocoder.geocode( { 'address': address }, function(results, status) {
  
            if (status == google.maps.GeocoderStatus.OK) {
              
            } else {
              alert('Geocode was not successful for the following reason: ' + status);
            }
      });
  }
  
  function addMarker(marker) {
      
  }
  </code></pre>
  <p>The problem now is the promise is already resolved before I get all the latitude and longitude. My sample output:</p>
  <p>It resolved the promise before all the item in the array get its latitude and longitude. By right it is supposed to be print out all details, followed by 'loop finish' and 'done promise'.</p>
  <p>How can I fix this?</p>