Includes property


I have a small question, about how the includes property works when the two comparable sides are array, for example here as attached, the result should be true
because [2,3] are including the bigger array [1,2,3,4], but as you can see I got false !!!

I would be appreciating to understand its concept, so does the engine compare each element of exc1 with all elements of numbers2, or it compares it as a block, so that if we change for example [3,2] instead of [2.3] it won’t find this block.

Thanks in advance.

Your smaller array does not include all the elements of your bigger array, so includes() returns false.

Thanks dear for your answer, but I did not get it actually, because the exercise was successfully executed, but I am a little bit confused related to the condition in red that contains “includes” property, so that I did this condition for the same two arrays alone to understand what Mosh here, so why he compares the smaller array with the bigger not the oppisite?

Mosh doesn’t pass an array to the includes() method but a single number and the if-condition checks if that number is not included in the array passed to the except() function. So what you do in your code snippet and what Mosh does in his is not quite comparable.

If you’re not sure what includes() does try reading it as “contains”. It returns true if the value(s) passed as an argument are included in the array it is called on, otherwise false. Or in other words: It returns true if the array it is called on contains the value(s) passed as an argument to it, otherwise false.

1 Like

Now I understood everything, thanks really for your help my dear