DEV Community

Discussion on: Includes() vs indexOf() in JavaScript

Collapse
 
misterwhat profile image
Jonas Winzen

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.

Collapse
 
johnsamuelob profile image
John Samuel Obinna

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