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

176
Vistas
When adding 1 to the index, at the point where I > array.length, undefined is returned. What am I doing wrong?

Currently, im adding 1 to the index on click, to simulate a user controlled iteration of the array. I have a conditional statement where if i > length, i = 0; Yet im still getting undefined after reaching the end of the array.

    const marqueeMonthlies = () => {
        intervalId = setInterval(() => {
            insertMarquee.empty('');
            // i %= marqueeMonthlyPlates.length
            insertMarquee.append(
                `<div class="container" id="generatedMonthlyPlates">
                <input type="text" width="100px" name="monthlyLicensePlate" id="${marqueeMonthlyPlates[i]}" class="licensePlate" placeholder="AB12345" value="${marqueeMonthlyPlates[i]}"/>
                </div>`
            )
            // i++;     
        }, 5000);
    }

    const getNextMonthly = () => {
        if ( i < marqueeMonthlyPlates.length) {
            i = i+1
            return marqueeMonthlyPlates[i]    
        } else
        if (i > marqueeMonthlyPlates.length){
            i = 0;
            return marqueeMonthlyPlates[i];
        } else 
        if (marqueeMonthlyPlates.length === undefined ){
            i = 0;
            return marqueeMonthlyPlates[i];
        }
        
    }

I tried to catch for when undefined present, to set the index back to 0, but it only corrects itself when 1 is added to i again on another click. What am I doing wrong here?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The answer was to change my greater than statement, as the goal was to bring i back to 0 when it reached the end.

        if (i > marqueeMonthlyPlates.length){
            i = 0;
            return marqueeMonthlyPlates[i];

to

        if (i >= marqueeMonthlyPlates.length){
            i = 0;
            return marqueeMonthlyPlates[i];
about 4 years ago · Santiago Trujillo 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