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

119
Views
¿Cómo podría hacer un bucle infinito para mostrar elementos de una matriz letra por letra?

Quiero hacer un bucle infinito para mostrar el mensaje letra por letra y elemento por elemento de una matriz. Alguien puede ayudar ??

 let textArr = ['first', 'second', 'third']; let i = 0; let j = 0; function spell() { if (j = 0) { clear(); } setTimeout(function() { show(); j + 0; if (j = textArr[i].length) { j = 0; i++; } if (i = textArr.length) { i = 0; j = 0; } spell(); }, 1000); } // clear the spelling function clear() { document.querySelector('#targ').innerHTML = ''; } // show the spelling function show() { document.querySelector('#targ').innerHTML += textArr[i][j]; } addEventListener('load', spell());
 <center id="targ"> </centre>

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

0

join su matriz en una cadena e itere a través de eso.

 const arr = ['first', 'second', 'third']; const targ = document.querySelector('#targ'); // Pass the array into the function function spell(arr) { // `join` it up const str = arr.join(' '); // Have an inner function that you call // from the setTimeout initialising the index to 0 function loop(i = 0) { // If the index is less than the string length // update the textContent of the element, and // increase the index if (i < str.length) { targ.textContent += str[i]; ++i; // Otherwise empty the textContent, // and set the index to zero } else { targ.textContent = ''; i = 0; } // Then call the loop function again with // the updated index as an argument setTimeout(loop, 200, i); } loop(); } spell(arr);
 <div id="targ"></div>

about 4 years ago · Juan Pablo Isaza Report

0

let textarr = ['first', 'second', 'third']; let i = 0 let j = 0 let str = textarr[0] setInterval(function() { i += 1 console.log( str.slice(0,i)) if(i == textarr[j%3].length){ i = 0 j += 1 str = textarr[j%3] } }, 1000);
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!