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

184
Visualizações
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 Respostas
Responde à pergunta

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 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