Have doubt in array.every() method

In the above code, I have given the condition (return e<4), my doubt is why is it returning 5 too.
Any help is greatly appreciated.

TLDR: As long as your callback returns true every will keep calling it.

Since 4<=4 i.e true, every callback will run for 5 element, which will log 5.
then 5<=5 will return false.
that’s when every will stop calling your callback function.

Try changing the example to e<=3, and see if the answer makes sense.

Also try adding 6, to the array.

Hope this helps. :slight_smile:

1 Like