title: setTimeout in forEach loop
body: <p>I want to delay making a call to another function in my forEach loop if a certain condition is met, but am not understanding setTimeout in this scenario.</p>
  
  <pre><code>function checkName(person) {
      console.log('checking name of ' + person.name)
      if (person.name === 'Julie') return true 
  }
  
  function checkPersons() {
      var persons = [
          {name: 'Bob', age: 21},
          {name: 'Frank', age: 15},
          {name: 'Julie', age: 12}
      ]
  
      var results = []
  
      persons.forEach(function(person) {
          if (person.age &gt;= 18) {
              console.log('do not need to check name of ' + person.name)
              results.push(person)
          } else {
              setTimeout(function() {
                  if (checkName(person)) {
                      console.log('Julie is ' + person.name)
                      results.push(person)
                  }
              }, 5000)
          }        
      }) 
  }
  
  checkPersons()
  </code></pre>
  
  <p><a href="https://jsfiddle.net/nicholasduffy/sy7qpqu1/1/" rel="nofollow">https://jsfiddle.net/nicholasduffy/sy7qpqu1/1/</a></p>
  
  <p>I get</p>
  
  <pre><code>do not need to check name of Bob
  // 5 second delay here
  checking name of Frank
  checking name of Julie
  Julie is Julie
  </code></pre>
  
  <p>I would like a 5 second delay each time I need to call <code>checkName</code></p>
  
  <pre><code>do not need to check name of Bob
  // 5 second delay here
  checking name of Frank
  // 5 second delay here
  checking name of Julie
  Julie is Julie
  </code></pre>