I have an Array with Moment.js objects in a variable:
var feriados = function addFeriados(){
feriados = [];
...
feriados.push(moment("2016-01-01"));
feriados.push(moment("2016-02-08"));
feriados.push(moment("2016-02-09"));
feriados.push(moment("2016-03-25"));
feriados.push(moment("2016-04-21"));
feriados.push(moment("2016-05-01"));
feriados.push(moment("2016-05-26"));
feriados.push(moment("2016-09-07"));
feriados.push(moment("2016-10-12"));
feriados.push(moment("2016-11-02"));
feriados.push(moment("2016-11-15"));
feriados.push(moment("2016-12-25"));
...
return feriados;
}
And a function to determinate if a value is in this array:
function checkFeriado(data) {
var i;
for (i = 0; i < allFeriados.length; i++) {
if (allFeriados[i] == data) {
return true;
}
}
return false;
}
But even if i pass a moment
object, as checkFeriado(moment("2016-01-01"));
i'm getting false. Whats wrong with my code? Is there a best way to do this?
Entire project have jQuery and Moment.js