-1

I have an array and I need to check if that array contains 2 and 3.

For example a = [1, 3].

I can do it with

a.includes(2) && a.includes(3)

I tried the following but I get inconsistent result, I don't understand why:

a.includes(1 && 3)
// true
a.includes(1 && 2)
// false
a.includes(2 && 3)
// true
1

1 Answer 1

1

a.includes(1 && 3) doesnot pass two arguments two the function. 1 && 3 is an expression which evaluates to the first falsy value value. If there is no falsy value the last value is returned. So 1 && 3 evaluates to 3

console.log(1 && 3) //3

You can use every()

[1,2].every(x => a.includes(x))
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.