Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
¿Cómo puedo hacer que un bucle foreach se detenga y espere un clic y luego continúe?
const arr = [object, object, object, object, object] arr.forEach(x => { object.proterty = myFunction(); }) function myFunction() { //click something //return what you click; }

mi código se ve así, el bucle forEach no espera el valor de retorno de myFunction

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puede intentar envolverlo en una promise y luego usar async/await

como esto

 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 Report

0

Creo que un bucle forEach no es lo que quieres. Un ciclo forEach está diseñado para iterar sobre un Array una vez para cada elemento. No hay forma de pausar un bucle además de lanzar una excepción.

Si quieres algo como esto, echa un vistazo a los siguientes métodos:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!