Skip to main content
Stack Overflow
  1. About
  2. For Teams

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

Required fields*

Array "includes" returns false, but item exists [closed]

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?

Answer*

Draft saved
Draft discarded
Cancel
4
  • Thank you, Alexander, the code weekends_test.includes(Number(day_of_week_curr)) also solved an issue, My reputation is low, so I cannot mark your answer as useful, but anyway, thank you. Commented Mar 6, 2025 at 12:16
  • 1
    @mplungjan i didnt read the comment, was answering and there's no rule that prohibits posting an answer that already covered in the comments, actually i encounter that's even encouraged 🤷‍♂️ Commented Mar 6, 2025 at 12:23
  • @mplungjan it's definitely not a typo, but a bug Commented Mar 6, 2025 at 12:23
  • 1
    We are missing the "this is trivial" and it is likely a dupe too Commented Mar 6, 2025 at 12:32

lang-js

AltStyle によって変換されたページ (->オリジナル) /