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

109
Visualizações
How to async await in promise.all

i wnna make an API thing that load list of pokemons and when it's image. got the list and wanna make sure the sequence on pictures will be correct for this i console.log the same names. and sequence is wrong. tried some async await in diff places and can't figure out how to get proper order https://codepen.io/DeanWinchester88/pen/ExvxdxX

Promise.all(arrForFetch)
    .then(files => {
        files.forEach(file => {
            console.log("files", file)
            process(file.json())
        })
            .catch(err => console.log("tobie pizda ucziekaj"))
    })
let process = (prom) => {
    console.log(prom)
    prom.then(data => {
        console.log(data.name)
    })
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const results = await Promise.all(arrForFetch)
// do something with results array

Your issue is that file.json() is async so needs to be returned from the loop as another Promise all, or awaited in the loop. You can map the promises.

Promise.all(arrForFetch)
                 .then( files  =>{
                     const more = files.map(file=>file.json().then(process))
                     return Promise.all(more)
                   })
                  .catch(err  =>  console.log("tobie pizda ucziekaj"))


Promise.all(arrForFetch)
                 .then( async files  =>{
                     for(const i=0; i<files.length; i++){
                     console.log("files", files[i])
                     process(  await files[i].json() )
                     }
                   })
                  .catch(err  =>  console.log("tobie pizda ucziekaj"))

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