Mel Pacheco
Mel Pacheco

Reputation: 789

date-fns check if date exist in array

I'm using date-fns, I can use helpers like isMonday(day) that returns true is if the day is a Monday, or isWithinRange(start, end) to check if a date is within a range, however, is there a way to return true if a date is in an array of dates?

Upvotes: 2

Views: 1284

Answers (1)

Jonas Wilms
Jonas Wilms

Reputation: 138257

To easy, just use Array prototype.some

 const dateInArray = (date, array) => array.some(d => +d === +date);

Upvotes: 2

Related Questions