I have a select-type in a form that is filled from the following array:
constructor(props) {
super(props);
this.state = {
timeslots:["17:00","17:15","17:30","17:45","18:00","18:15","18:30","18:45","19:00"],
}}
If this date is known in the database with the same time slot, it must filter out this time slot. Now he only takes 1 value out on 1 day.
So for example I have the array:
this.state.timeslotsDisabled: ["17:00","17:30"]
and there I want to filter out the following value with this function:
handleDayClick(day) {
this.setState({
timeslots: this.state.timeslotsReset
})
for(let i = 0; i< this.state.timeslotsDisabled.length; i++){
if(new Date(this.state.timeslotsDisabled[i].date).getFullYear() == day.getFullYear() && new Date(this.state.timeslotsDisabled[i].date).getMonth() == day.getMonth() && new Date(this.state.timeslotsDisabled[i].date).getDate() == day.getDate()){
console.log('same');
console.log('GONE:'+ this.state.timeslotsDisabled[i].time)
this.setState({
timeslots: this.state.timeslots.filter((item)=> item !== this.state.timeslotsDisabled[i].time),
})
}else{
console.log('else');
}
}
this.setState({
selectedDay: day,
});
}
But he only filter 1 value like this:
So I would expect that both "17:00" and "17:30" would no longer be visible. And as you can see, only 17:00 is no longer available. If I have 1 value it works. Can someone tell me what I'm doing wrong?