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?

Hassle-free blogging platform that developers and teams love.
  • Docs by Hashnode
    New
  • Blogs
  • AI Markdown Editor
  • GraphQL APIs
  • Open source Starter-kit

© Hashnode 2024 — LinearBytes Inc.

Privacy PolicyTermsCode of Conduct