Question

I'd like this to repeat the objects' value in the array 31 times.

Is there a way to do that with a $.each statement, or just a regular js for loop?

thanks

dayz = 31;

var numberArray = [{obj:1}, {obj:2}, {obj:3}, {obj:4}, {obj:5}];
jQuery.each(numberArray , function(index, value){
  console.log(numberArray[index%dayz]); 
});
Was it helpful?

Solution

I apologize if I misunderstand your question. But it seems you just want to repeat your numberArray 31 times, console it out.

dayz = 31;

var numberArray = [{obj:1}, {obj:2}, {obj:3}, {obj:4}, {obj:5}];
jQuery.each(new Array(dayz), function(i){
     jQuery.each(numberArray, function(idx, val){
         console.log(numberArray[idx%dayz]); 
     })
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top