Sign in
Log inSign up

What's the best alternative to indexOf() for checking existence of element in an array?

James B's photo
James B
·May 11, 2016

In most languages, indexOf() returns -1 if element is not found, which IMO is a bit counter productive. What's the best alternative to this in you programming language? Is there any function that will just return a boolean value indicating if the element was found?