title: JavaScript - axios GET request, push to array but return error with promise.all
body: <p>I'm trying to make GET request to a free API and return an array of all French departments as a result. Initially, I was getting empty result, which then I understood I wasn't wait for GET request to end. So I used the promise.all to make sure it waited but it doesn't work, I still get errors and undefined result. This is the code:</p>
  <p>make array of departments:</p>
  <pre><code>const axios = require('axios')
  
  let postalCode_all = []
  
  for(let i = 1; i &lt; 97; i++) {
  
      if(i &lt; 10){
          postalCode_all.push(&quot;0&quot; + i)
      } else {
          postalCode_all.push(i)
      }
  }
  </code></pre>
  <p>Prepare the GET request to API:</p>
  <pre><code>let departements = [];
  
  async function use_api(dep)  {
  
          try {
              const response = await axios.get(&quot;https://geo.api.gouv.fr/departements/&quot; + dep + &quot;?fields=region&quot;);
              departements.push(response);
  
          } catch (err) {
              console.error(err);
          }
      };
  </code></pre>
  <p>Make the GET request on all of the array firstly made:</p>
  <pre><code>(async () =&gt; {
      const result = await Promise.all(
          postalCode_all.map(element =&gt; {
              return use_api(element);
          })
      )
      console.log(result)
  })()
  </code></pre>
  <p>Edit:
  Errors (404) probably comes from departments like number 20 that doesn't exist, so I think my real issue is array of undefined, I will think about it.</p>