title: Problem with firebase function it is returned undefined value in a async function
body: <p>I am creating a function in firebase that calls other functions. This call is made asynchronously one by one. When I call the <strong>"foreachhours()"</strong> function it uses a loop to call another function called <strong>"getfilterhours()"</strong>. When I bring the data from <strong>"getfilterhours()"</strong>, when it is printed on screen it works correctly. But when I assign it to a variable it tells me that I need a promise, that's why there is the .then after the call. The problem is that when I return the Ddr data the result is either undefined or an empty [] array. What options do I have to return that value without it showing up with nothing?.</p>
  
  <pre><code>async function foreachhours(horasselected: any,key: any){
  let ress: any[][]=[];
  let Ddr: any[][]=[];
  //differents queries, in english horas is equal to "hour"
  await horasselected.forEach(async function(hora: { hora: any; }){
      await getfilterhours(hora.hora,key).then(function(res){
          res=[];
          ress.push(res);//res=[{horas:["6:00","9:00"]}]
      });
   //&lt;----The problem is start here---&gt;
   //expected value is [{horas:["6:00","9:00"]},{horas:["5:00","12:00"]}, 
   //{horas:["6:00","19:00"]}
      Ddr.push(ress);//undefined or[]
  });
  console.log(Ddr);//undefined or []
   return Ddr;//undefined or []
  }
  //Function to get especific values from a querie in firestore
  async function getfilterhours(hora: any,key: any){
  var db = admin.firestore();
  var elementosaux: any[] = [];
  var elementoselement;
  
  await db.collection("pedidos_servicios").where("key","==",key)
      .where("horas","array-contains",hora).get().then(snapshot=&gt;{
          snapshot.forEach(doc3=&gt;{
             elementoselement = {
                  "horas": doc3.data().horas
              }
              elementosaux = elementosaux.concat(elementoselement);
          });
      }).catch((e)=&gt;console.log(e));         
  return elementosaux;//elementosaux=[{horas:["6:00","9:00"]}]}
  </code></pre>
  
  <p>Thanks for your help!:)</p>