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

120
Visualizações
How to reset interval of set interval function

I'm wondering how to stop this function when next is not equal to targetVar and here's my code :

function detectChange(next,targetVar){
    if (next==targetVar){
        waktuSholat();
        console.log("Waktu Sholat Berhasil Di Perbarui");
    } else if (next!=targetVar){
        speakIt();
    }
}
setInterval(detectChange, 2000);

I don't know how to stop this interval. I really appreciate your help and your suggestion.

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

0

Store the id returned by setInterval and call clearInterval to stop it. Note that detectChange is called each time without any arguments, so both next and targetVar are always undefined; perhaps you meant to check global variables instead.

function detectChange(next,targetVar){
    if (next==targetVar){
        waktuSholat();
        console.log("Waktu Sholat Berhasil Di Perbarui");
    } else {
        speakIt();
        clearInterval(id);
    }
}
let id = setInterval(detectChange, 2000);
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