Skip to content
Advertisement

How to compare two Moment.js Objects

I have an Array with Moment.js objects in a variable:

JavaScript

And a function to determinate if a value is in this array:

JavaScript

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

Advertisement

Answer

JavaScript

Javascript objects cannot be compared like this, same with moment’s javascript objects. Moment has its own implementation to check if dates are equal. use isSame

JavaScript

You can also use Array.filter to check this.

I wonder if you meant fearadios = allFeradios() as in a function call?

allFeradios.length doesn’t sound right in your example! as it is a function name, so is feradios.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement