Can't you use a for loop?
for ( var i=0; i< boxes.length; i+=4 ) {
I am not big jQuery, but in normal JavaScript that will work fine.
EDIT: You changed the problem a bit, so you want to act on each element, but do something specific on the fourth ...
var previousTop; for ( var i=0; i< boxes.length; i++ ) { // do stuff with boxes[i] if ( ( (i+1) % 4 ) === 0 ) { previousTop = boxes[i].position.top; // do stuff with the fourth item } }
Here, the wider scope of previousTop then set every fourth element before doing whatever you need. Then, when you reach the next fourth element, you have the value from the previous in your temporary variable, which looks like what you are looking for, from your answer to @patrick dw below.
glenatron
source share