Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

172
Views
Al agregar 1 al índice, en el punto donde I > array.length, se devuelve undefined. ¿Qué estoy haciendo mal?

Actualmente, estoy agregando 1 al índice al hacer clic, para simular una iteración controlada por el usuario de la matriz. Tengo una declaración condicional donde si i > longitud, i = 0; Sin embargo, sigo sin definirme después de llegar al final de la matriz.

 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]; } }

Traté de detectar cuando no está definido presente, para volver a establecer el índice en 0, pero solo se corrige solo cuando se agrega 1 a i nuevamente en otro clic. ¿Qué estoy haciendo mal aquí?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

La respuesta fue cambiar mi declaración mayor que, ya que el objetivo era devolver i a 0 cuando llegara al final.

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

a

 if (i >= marqueeMonthlyPlates.length){ i = 0; return marqueeMonthlyPlates[i];
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!