Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

86
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda