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

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

0

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