DEV Community

Discussion on: JavaScript Array methods

Collapse
 
jimhol profile image
jimhol

indexOf is good when you need the index. If you just want to know whether the value is in the array or not, you then have to test the result against -1. Alternatively you could use .includes() to get true or false directly.

Collapse
 
shreyazz profile image
Shreyas Pahune

Yup that’s correct! But indexOf tells you precisely where the value is found…✅