title: How to execute promises sequentially, passing the parameters from an array?
body: <pre><code>var myArray = [1, 2, 3, 4, 5, 6]
  
  function myPromise(num){
    return new Promise(res =&gt; {
      window.setTimeout(()=&gt;{
        res(  console.log("done: " + num)  )
      },2000)
    })
  }
  
  
  myPromise(myArray[0])
    .then(x =&gt; myPromise(myArray[1]))
    .then(x =&gt; myPromise(myArray[2]))
    .then(x =&gt; myPromise(myArray[3]))
    .then(x =&gt; myPromise(myArray[4]))
    .then(x =&gt; myPromise(myArray[5]))
  </code></pre>
  
  <p>Right now, if I execute the statement above, it will run sequentially. In my actual use case the array is dynamically populated and I need to execute the <code>myPromise()</code> function for each member in <code>myArray</code>.</p>
  
  <p>How can I make a "pauseable loop" that will loop for each item in the array, execute <code>myPromise</code> and wait for the promise to be resolved before continuing to the next iteration?</p>