Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda