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

134
Vistas
how do I use async await in a regular for loop

I have a function that accepts a game found from a mongodb database via mongoose and the number of bots to add to the game object. the problem is after running the function only one bot object is being saved to the document even thought numOfBots is 3

async function addBot(game, numOfBots){

  for(index = 0; index < numOfBots; index++){
    let bot = {nickName: "Bot"}
    game.players.push(bot)
    game = await game.save()
  }
  return game
}

// elsewhere in another async function 
await addBot(game,3)

How can I use async await correctly in a regular for loop?

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