This is the exact purpose for which the modulo operation was designed...
It's important to note that you cannot have two different indexes in your array. It wouldn't make sense, as they would have the same value anyway.
Instead, utilize the modulo operator (known as such in French, not sure about the translation):
<div *ngFor="let item of items; let i = index">
<span *ngIf="i % 7 === 5">It's Saturday!</span>
</div>
Snippet:
const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
const month = [...days, ...days, ...days, ...days];
month.forEach((day, i) => {
if (i % 7 !== 5) { return; }
console.log(day);
});
EDIT ONE When dealing with an unordered array of days, the best approach to "reset an index" is to split your array into multiple ones.
If you want to reset on Saturdays, consider something like this:
array=["monday","monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday", "saturday", "sunday"];
splitted = this.array.reduce((p, n) => {
if (n === 'saturday') { p.push([n]); return p; }
p[p.length - 1].push(n);
return p;
}, [[]]);
<p *ngIf="options != 'saturday' ">
{{i}}. First category: Value{{i}}
<p>
<p *ngIf="options == 'saturday'" style="color:red">
{{i}}. Saturday: Value{{i}}
</p>
</div>
Check out the updated stackblitz.
EDIT TWO Hopefully, this is the correct solution now! Simply create a counter with a getter method and reset the counter to zero once the lifecycle is completed.
private counter;
get saturdayCounter() {
return this.counter++;
}
ngAfterContentChecked() {
this.counter = 0;
}
<p *ngIf="options == 'saturday'" style="color:red">
{{i}}. Saturday: Value{{saturdayCounter}}
</p>
View the working stackblitz here.