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

162
Vistas
Async function with multiple fetch in an array - Best way to do that?

I'm learning JavaScript and async functions is not my strength.

I have an array of gameIds, and I have to fetch each individual id and get the data of all that games.

async function gameInfo() {
    gamesIds = [19,12,13,15,16];

    //what should be here?

    const response = await fetch(`http://localhost:8080/game/${individualGameId}`, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
        withCredentials: true,
        credentials: 'include',
        "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5c"
      },
    });

    const allGamesInfo = await response.json();
    console.log(allGamesInfo);
}

Can someone help me with this ?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The best idea for your problem is creating a Array of Promises and execute it with Promise.all

gamesIds = [19,12,13,15,16];

    const promises = gamesIds.map(id =>                 
      fetch(`http://localhost:8080/game/${id}`, {
        method: 'GET',
        headers: {
          'Content-Type': 'application/json',
          withCredentials: true,
          credentials: 'include',
          "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5c"
        },
    }))

    const response = await Promise.all(promises);

about 4 years ago · Juan Pablo Isaza Denunciar
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