title: How do I wait for a promise's "then" block to execute within nested forEach loops before the loops iterate again?
body: <p>I have 3 total forEach loops and I want the first two to wait on a promise's then block to execute before they start over and iterate again. I've demonstrated this with console.log statements labeled 1, 2, and 3.</p>
  
  <p>I want the console logs to go in order, like "1, 2, 3, 1, 2, 3 etc" 
  Instead what I'm getting is "1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 3, 3, 3, 3, 3, 3"
  How do I make all of this sequential?
  fetchCandidatesByCity is the mongoose find method, which returns a promise.</p>
  
  <pre><code>axios.get(FEED_URL).then(data =&gt; {
  let candidatesWithMessageSent = [];
  
  data.data.jobs.forEach(job =&gt; {
    console.log("1");
    // console.log(candidatesWithMessageSent);
    job.city.forEach(cityAndState =&gt; {
      console.log("2");
  
      let jobState = extractState(cityAndState);
  
      let jobLocation = addSpaceAfterComma(cityAndState.toLowerCase());
  
      let jobCity = extractCity(jobLocation);
  
  
      fetchCandidatesByCity(jobCity)
        .then(candidates =&gt; {
          candidates.forEach((candidate, index) =&gt; {
            console.log("3");
            const candidateId = candidate._id.toString();
  
            if (index &lt;= MAX_MESSAGE_LIMIT &amp;&amp;
              !containsUberLyft(job.title) &amp;&amp;
              priceIsHigh(job.price) &amp;&amp;
              !candidateHasMessage(candidatesWithMessageSent, candidateId)) {
  
              const jobURL = `http://www.jobs2careers.com/click.php?id=${job.id}.${PUBLISHER_ID}`;
  
              // candidate has received a job notification, so add candidate to candidatesWithMessageSent
  
              candidatesWithMessageSent = [ ...candidatesWithMessageSent, candidateId ];
  
            }
            return;
          });
        })
        .catch((error) =&gt; {
          console.log(error);
        });
    });
  });
  </code></pre>
  
  <p>});</p>