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

260
Views
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 answers
Answer question

0

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