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

226
Visualizações
how can i make a foreach loop to stop and wait for a click then continue?
const arr = [object, object, object, object, object]

arr.forEach(x => {
     object.proterty = myFunction();
})

function myFunction() {
  //click something
  //return what you click;
}

my code looks like this, the forEach loop it doesnt wait for the return value from myFunction

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

0

You can try to wrap it in a promise and than use async/await

like this

const arr = [object, object, object, object, object]

arr.forEach(x => {
     object.proterty = myFunction();
})

function myFunction() {
  return new Promise((resolve) => {
     //click something
    const clickedItem = .... 
    //resolve what you click;
    resolve(clickedItem)

  })
  }

about 4 years ago · Juan Pablo Isaza Relatório

0

I think a forEach loop is not what you want. A forEach loop is designed to iterate over an Array one time for each element. There is no way to pause a loop besides with throwing an exception.

If you want something like this maybe take a look in the following methods:

Array.prototype.every()
Array.prototype.some()
Array.prototype.find()
Array.prototype.findIndex()

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach

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