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

283
Visualizações
Promises.all() - how to check if all return undefined

In the following code, I want to check if the promisesArray returns any data.

const promisesArray = [this.loadData1(),this.loadData2()]

Promise.all(promisesArray).then(() => {
 console.log('promises.all callback -> ', promisesArray[0])
}

The above console.log can produce the following:

Promise {<fulfilled>: undefined}
[[Prototype]]: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: undefined

If I do not specify index 0, it repeats the same output for both function calls passed to Promises.all.

I am trying to access the undefined value in both the responses but not sure how to with with each key being a multi-dimensional array.

If anyone has any ideas on how to easily check if both functions result in undefined I would be very grateful.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Promise.all(promisesArray)
  .then((res) => res.every((r) => r === undefined))
  .then((isUndefined) => {
    // if isUndefined is true then all promises returned undefined
  });

about 4 years ago · Juan Pablo Isaza Relatório

0

Using async / await syntax:

const results = await Promise.all([this.loadData1(),this.loadData2()]);

if (results.every(r => r === undefined)) {
  console.log('No data!');
}

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