I have an array of dates returned from an API. For example, I might have an array entitled validDates
that has all of the Mondays in September as their values. I would like to use the Material Datepicker filter to only allow date values in the array to be selected.
Example Date Array
validDates = [
Mon Sep 02 2019 00:00:00 GMT-0500 (Central Daylight Time),
Mon Sep 09 2019 00:00:00 GMT-0500 (Central Daylight Time),
Mon Sep 16 2019 00:00:00 GMT-0500 (Central Daylight Time),
Mon Sep 23 2019 00:00:00 GMT-0500 (Central Daylight Time),
Mon Sep 30 2019 00:00:00 GMT-0500 (Central Daylight Time)
]
Datepicker Filter (not working)
myFilter = ( d: Date ): boolean => {
let dateOpen: boolean;
for ( let x = 0; x < this.validDates.length; x++ ) {
dateOpen = d.toString() === this.validDates[ x ].toString();
}
return dateOpen;
}
The issue is it only returns the last date (Mon Sep 30 2019 00:00:00 GMT-0500 (Central Daylight Time)) as true
so that only the 30th becomes selectable. I want each of the dates in the array to be selectable.
How can I return true
for each value in the array?