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

250
Views
Dividir el valor del área de texto en una matriz, luego hacer un bucle y ejecutar la función

Estoy intentando:

  • Tomar la entrada de un área de texto
  • Dividir en una matriz de cadenas, siendo cada línea un elemento de esa matriz
  • Recorra cada elemento de esta matriz, ejecute una función que use el texto en el elemento actual, luego espere 5 segundos antes de pasar a la siguiente iteración/elemento de bucle.

Desafortunadamente, todos mis intentos hasta ahora no han funcionado, soy un principiante en JS, así que estoy tomando fragmentos y haciendo mi mejor esfuerzo aquí:

 // var LS = document.querySelector('textarea').value().split('\n'); for (let i in LS) { setTimeOut(function(i),5000); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

 textInput = document.getElementById("theText"); textArray = textInput.value.split(/\n/g); const delayLoop = (fn, delay) => { return (line, i) => { setTimeout(() => { useTheText(line); }, i * 5000); } }; function useTheText(line){ console.log(line); } const handleClick = () => { textInput.value.split(/\n/g).forEach(delayLoop(useTheText, 500)); }
 <textarea id="theText" name="theText" rows="5" cols="33"> It was a dark and stormy night... second line line 3 </textarea> <div> <button onClick="handleClick()">process</button> </div>

about 4 years ago · Juan Pablo Isaza Report

0

El primer argumento de setTimeout() debe ser una función para llamar. Estás llamando a la función inmediatamente.

Si desea que se ejecuten con 5 segundos de diferencia, multiplique el valor del tiempo de espera por i . El tiempo de espera se mide desde que llamas a setTimeout , no desde que se ejecutó la función anterior.

 for (let i in LS) { setTimeout(() => yourFunction(LS[i]), i * 5000); }
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!