title: React + Typescript: setTimeout in For Loop is not populating array consecutively, or at all
body: <p>I'm building a function that makes images of random cars animate across the screen, and I want to stagger the population of the &quot;carsLeft&quot; array with a setTimeout..(which I will ultimately randomize the delay time).</p>
  <p>everything works until I try to use a setTimeout. With the code below, no cars get are shown. a Console.log shows that the &quot;carsLeft&quot; array does not populate. When I remove the setTimeout all the cars are shown (at once of course). I have tried IIDE still no luck. Been stuck on this one for awhile, Please Help!</p>
  <pre><code>function Traffic() {
    let carsLeft: any = [];
    const generateCarLeft = () =&gt; {
      for (let i = 0; i &lt; 5; i++) {
        setTimeout(() =&gt; {
          carsLeft.push(
            &lt;CarLeft key={i} className=&quot;car__left&quot;&gt;
              &lt;img
                src={carListDay[Math.floor(Math.random() * carListDay.length)]}
                alt=&quot;&quot;
              /&gt;
            &lt;/CarLeft&gt;
          );
        }, 3000);
      }
    };
  
    generateCarLeft();
    return &lt;div className=&quot;traffic__container&quot;&gt;{carsLeft}&lt;/div&gt;;
  }
  
  export default Traffic;
  </code></pre>