re: Includes() vs indexOf() in JavaScript VIEW POST


Nice article.
I have one correction for you.

The line:
if(array.indexOf(4) >= -1 )

Needs to be:
if(array.indexOf(4) > -1 )

In order to check, whether an element is in the array. Otherwise the condition would always be true.


Yeah. indexOf() always return -1 if element is not found. Thanks Jonas

Code of Conduct Report abuse