Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

87
Visualizações
JavaScript Array

So I have Been Writing this function all night, its goal is to find and sort data from two tables and then return an array of objects containing my needed data But the array keep showing empty

 router.post('/find/', (req,res,next)=>{
  try {
     // Return an array of Hotels in the Region
    hotels.find({region:"wuse"}).then(hotel=>{
      const finalArr = []
      for(var i = 0; i< hotel.length;i++){
        rooms.find({hotel:hotel[i]._id,price:{$lt : 29000}}).then(rooms=>{
          for(var j = 0; j <rooms.length; j++ ){
           // Push to the arr 
            finalArr.push(rooms[j])
            console.log(rooms[j]);// Its Works 
          }
        }).catch(err =>{
          console.log(err);
        })
      }
      console.log(finalArr);// And This Return [] an Empty Array
      res.end()
    }).catch(err =>{
      console.log(err);
    })
  } catch (error) {
    console.log(error);
  }
})

I have used Async/await, append(), forEach() and Promise.all()

any solution would.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda