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

268
Vistas
jQuery: Start from first value if values are not there

So I have this array in JS

var values = ["rgb(236,221,208)","rgb(146,177,182)","rgb(191,209,223)","rgb(187,237,190)"];

This array has 4 values, and it is used to add background color to some sections

$(".class").each(function(index) {
    var color = values[index];
    $(this).css("background-color", color);
});

Suppose if we have 6 rows to add background color, then in that case values[4] and values[5] will be undefined

I want to know is there any method in which we can start over the array values once we reach the end? means once we reach the point where values[4] is undefined so instead of it we can continue with values[0] and so on

values[0], values[1], values[2], values[3], values[0], values[1], values[2] ..........

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

$(".class").each(function(index) {
    var color = values[index % values.length] ;
    $(this).css("background-color", color);
});
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