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