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

125
Visualizações
¿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 Respostas
Responde à pergunta

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 Relatório

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 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