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

148
Views
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
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!