How to search an array in JavaScript

Today you will learn how to search an array in JavaScript. Here, we will discuss four different methods to search for an item in an array using JavaScript.

Way to search an array in JavaScript

  1. Filter
  2. Find
  3. Includes
  4. IndexOf

1. Filter

The Array.filter() method creates a new array with all elements that pass the test implemented by the provided function.

2. Find

The Array.find() method returns the value of the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.

3. Includes

The Array.includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

4. IndexOf

The Array.indexOf() method returns the first index at which a given element can be found in the array, or -1 if it is not present.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *