There are some problems with your code.
I would recommend using the strict mode. 'use strict';
which eliminates some JavaScript silent errors by changing them to throw errors.
Read more about it here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode
Currently, you have your defined your variables like so.
dateNumber = [23, 25];
show = true;
Although it works but these are leaked globals. When you declare variables without var
, let
, or const
. JS creates that variable in the global scope.
You should always use var
, let
, or const
to define your variables.
Read more about it here: https://www.freecodecamp.org/news/var-let-and-const-whats-the-difference/
Also use the strict equality operator instead of ==
Read more about it here: Which equals operator (== vs ===) should be used in JavaScript comparisons?
Try this:
'use strict';
const date = new Date();
const dateNumber = [23, 25];
let show = false;
if (service === '7305') {
for (let i = 0; i < dateNumber.length; i++) {
if (date.getDate() === dateNumber[i]) {
show = true;
break;
}
}
}