title: call two promises in the .then() clause in javascript
body: <p>I have one promise which when it resolves, it will return "ResponseA" and in the .then() clause it is suppose to call two other promise and when they fulfill, it should print out the values(tgResponse.length and igResponse.length). But the problem is, it is always printing the value of last promise and skipping the first one which is console.log('igResponse', igResponse.length);
  Why this happens? and how can I make sure that it runs igApiPromise and tgApiPromise in parallel and prints the value for both of them. Thanks a lot for your help. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>new Promise((resolve, reject) =&gt; {
              /// do some stuff
                      resolve(responseA)
                  }
              });
          }).then(ResponseA =&gt; {
              console.log(ResponseA.Values);
              igApiPromise(ResponseA.Values.token).then(igResponse =&gt; {
                  console.log('igResponse', igResponse.length);
              });
              tgApiPromise(ResponseA.Values).then(tgResponse =&gt; {
                  console.log('tgResponse', tgResponse.length);
              });  
           });
  
          let igApiPromise = token =&gt; {
              return new Promise(function (resolve, reject) {
                  console.log('lotfan');
                  xhttp.open("GET", "/api/igconfig", true);
                  xhttp.setRequestHeader("Authorization", `Bearer ${token}`);
                  xhttp.onload = function () {
                      if (this.status &gt;= 200 &amp;&amp; this.status &lt; 300 &amp;&amp; this.readyState == 4) {
                          resolve(xhttp.response);
                      } else {
                          reject({
                              status: this.status,
                              statusText: xhttp.statusText
                          });
                      }
                  };
                  xhttp.onerror = function () {
                      reject({
                          status: this.status,
                          statusText: xhttp.statusText
                      });
                  };
                  xhttp.send();
              });
          }
  
          let tgApiPromise = token =&gt; {
              return new Promise(function (resolve, reject) {
                  xhttp.open("GET", "/api/tgApidata", true);
                  xhttp.setRequestHeader("Authorization", `Bearer ${token}`);
                  xhttp.onload = function () {
                      if (this.status &gt;= 200 &amp;&amp; this.status &lt; 300 &amp;&amp; this.readyState == 4) {
                          resolve(xhttp.response);
                      } else {
                          reject({
                              status: this.status,
                              statusText: xhttp.statusText
                          });
                      }
                  };
                  xhttp.onerror = function () {
                      reject({
                          status: this.status,
                          statusText: xhttp.statusText
                      });
                  };
                  xhttp.send();
              });
          }
  </code></pre>