I have an array:
public roundRobinMonths: any=['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
and another empty array: public userTimeline: any=[];
My user will select a month from a datepicker and if he selects say September then I want to add months starting from Oct until Sep in my userTimeline array i.e. Oct, Nov,..., Apl, Mai,..., Aug, Sep
I receive in my component index for a month that user selects i.e. 0, 1,.., 11.
I tried running a for loop like following:
public pickDate($event: MouseEvent) {
this.datePicker.selectDate(this.selectedWeddingDate, {openFrom: $event}).subscribe( (selectedDate: Date) => {
this.selecteDate = selectedDate ? moment(selectedDate) : null;
// logic for creating personalized timeline
switch (this.selectedDate.month()) {
case 8:
for(let month of this.roundRobinMonths){
if(this.roundRobinMonths.indexOf(month)===8){
this.userTimeline.push(month)
console.log(this.userTimeline)
}
}
break;
default:
// code...
break;
}
});
}
This adds only one month. What could be the correct logic?