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

149
Visualizações
Can I change the time of a setInterval after each interation?

I have this code where it runs through all the categories sends a post (console log) and once it reaches the end it will restart. I am trying to find a way for each subsequent category to be delayed by a certain amount of time. (for testing purposes 1 second, but ultimately 1 hour) I tried to use a function as well as taking the function contents out and do it separately.

// I put this above const CategoryTimer
let defaultTime = 1000;
let time = defaultTime + (curPost * 1000);
// And then I put time in place of CategoryTime(curPost) below.

I'm pretty confused as to what to do but once I figure this part out I can finally get this project back on track. Thank you all in advance!

// Command
let curPost = 0;
const CategoryTimer = setInterval(() => {
  // Database Call
  let categories = ["sad", "toebeans", "meows", "tucked", "smol", "chonky"];
  
  // Make post
  console.log(`Post for ${categories[curPost]}`);

  if (curPost === categories.length - 1) {
    curPost = -1;
    console.log("Restart!");
  }

  curPost++;
}, CategoryTime(curPost));

function CategoryTime(curPost) {
  let defaultTime = 100000;
  return defaultTime + (curPost * 1000);
}
about 4 years ago · Juan Pablo Isaza
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