javascriptmomentjs

Array "includes" returns false, but item exists


What am I doing wrong?

Here is my code:

let weekends_test=[6,5];
let day_of_week_curr=moment.unix(curr_time).format('e'); //returns 6 (I'm using moment.js library)
console.log (weekends_test.includes(day_of_week_curr)) //returns false, but true expected

indexOf instead includes returns "-1"

Maybe other way to find a value exists? Except "for" cycle?


Solution

  • moment.format returns a string, so you should convert it to a number:

    let day_of_week_curr=parseInt(moment.unix(curr_time).format('e'));