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

165
Visualizações
Is there a way to find out total number of times setInterval() executed for a particular function inside Javascript code using any command

I have a function say main() which uses setInterval(async()=>{ console.log("Hello")},1000). The function inside setInterval() is executed 13 times i.e. Hello is printing 13 times. I want to check the value or the number of time this setInterval is running. Is there any way to do that?

main(){
   setInterval(async()=>{
              console.log("Hello")
              await someApiCall();
              console.log("World");
              await anotherApiCall();
    },1000)
}

This main function can be called multiple times. Can that be causing the number of print statement to increase.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can keep a track of it using some counter.

If you want to keep track of setInterval across multiple calls of the main function.

let count = 0;

const main = () => {
  setInterval(async() => {
    console.log("Hello")
    count++
    console.log(count)

  }, 1000)
}

main()
main()

If you want to keep track of setInterval within the main function.

const main = () => {
  let count = 0;
  setInterval(async() => {
    console.log("Hello")
    count++
    console.log(count)

  }, 1000)
}

main()

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