I have this code:
-
For index try this:
Controller File add function :
chunks(array, size) {
let results = [];
while (array.length) {
results.push(array.splice(0, size));
}
return results;
};
In you view file :
This will work for all number , not only %3 numbers.
@Teddy Sterne's solution will work incase of the number is %3
If we have 8 products it will show only 6 last 2 will be lost , in this it will also be shown.
And it will create extra blank div tags for not %3 index , if you inspect the element and check , because it will loop through each product and div will get repeated no matter if its index %3 or not.