How to perform a function after each 10 element of the array?

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?

\$('.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
});
June 14th 19 at 18:23
June 14th 19 at 18:25
\$('.item').each(function(index) {
if(index < 10) {
// the first 10
} else {
// the rest
}
});
but if elements 90 and after each 10s? and at the end for balance? - dereck_Durg commented on June 14th 19 at 18:28
what "after every 10s"?
Tenth, twentieth, thirtieth and so on? Or the eleventh, twenty-first, thirty-first..? - Austen.Thompson53 commented on June 14th 19 at 18:31
Tenth, twentieth, thirtieth and so on - that
and then for the remaining, if for example 97 for the remaining 7 - dereck_Durg commented on June 14th 19 at 18:34
\$('.item').each(function(index) {
if (!((index + 1) % 10)) {
// tenth, twentieth...
}
}).each(function(index) {
if ((index + 1) % 10) {
// the rest
}
});
- Austen.Thompson53 commented on June 14th 19 at 18:37
, 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
thank you! - dereck_Durg commented on June 14th 19 at 18:43
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