how to run the following code?

to perform the function for every 10 items, and then for those that in the end there will be?

to perform the function for every 10 items, and then for those that in the end there will be?

```
$('.item').each(function(index) {
myObj.myMethod(this);
if(index%10) {
// execute the function for packs of 10 items
myFunc();
}
// after execute it for the remaining, which are non-multiple of 10
});
```

asked June 14th 19 at 18:23

2 answers

answered on June 14th 19 at 18:25

```
$('.item').each(function(index) {
if(index < 10) {
// the first 10
} else {
// the rest
}
});
```

answered on June 14th 19 at 18:27

```
$('.item')
.filter(function(index) {
return index%10 === 0;
}).each(function(index, element) {
myFunc();
});
$('.item')
.filter(function(index) {
return index%10 !== 0;
}).each(function(index, element) {
myObj.myMethod(this);
});
```

Find more questions by tags JavaScript

Tenth, twentieth, thirtieth and so on? Or the eleventh, twenty-first, thirty-first..? - Austen.Thompson53 commented on June 14th 19 at 18:31

and then for the remaining, if for example 97 for the remaining 7 - dereck_Durg commented on June 14th 19 at 18:34

Normally to describe a condition, not destiny? This I now the third piece of meaningless code to write, and once it turns out that that's not all! - Austen.Thompson53 commented on June 14th 19 at 18:40