Reputation: 2290
I am wanting true
or false
return when using includes
to see if the current month using moment().format('MMMM')
is also in an array
.
const splitMonths = ['April', 'May', 'June', 'July', 'August', 'September'];
const currentDate = moment().format('MMMM');
const seasonData = currentDate.includes(splitMonths);
console.log(seasonData);
The above returns false
and I cannot understand why.
If I change splitMonths
to splitMonths = ['May'];
it will return true
.
If I run console.log(currentDate)
it returns May
.
Why isn't this returning true
?
Upvotes: 1
Views: 31
Reputation: 7891
You are checking array existence within the string currentDate.includes(splitMonths);
. Instead it should be splitMonths.includes(currentDate);
const splitMonths = ['April', 'May', 'June', 'July', 'August', 'September'];
const month = "May";
const seasonData = splitMonths.includes(month);
console.log(seasonData);
Upvotes: 1