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

179
Vistas
How to create dynamically variable for setInterval?

I create a hmtl page with node and ejs with an unforseeable number of elements. I would like to create a setInterval for some, none or all of those elements, depending what the user is doing.

The problem is, that I am not able to create a dynamically variable for the setInterval so that I can later on cancel those Intervals.

Maybe I just need another simpler approach but at the moment I am stuck here.

camContainer.forEach(element => {
        clearInterval(intervalVar);
        if (!element.classList.contains("hidden")) {
            countVisible++;
            intervalVar = setInterval(showConsole, 1500);
        } else {
            countHidden ++;
        }
    count++;    
    })

I tried it with an Array instead of a regular variable but that didnt work either

intervalVar[count] = setInterval(showConsole, 1500);
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You're on the right track with an array, but you need to push items onto it:

intervalVar = []

// ...

intervalVar.push(setInterval(showConsole, 1500))

When you want to cancel an interval, remove it from the array with slice or pop, depending on how you're selecting the item to cancel.

about 4 years ago · Juan Pablo Isaza Denunciar
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