JavaScript Array Search

JavaScript Tutorial

JavaScript Array Search

In JavaScript Array Search provides several methods to search for elements in an array — such as checking if a value exists, finding its index, or returning the matching value.


 1. indexOf() – Find Index of Value

Returns the index of the first matching element.
If not found, it returns -1.


 


 2. lastIndexOf() – Find Last Occurrence

Works like indexOf() but searches from the end.



 3. includes() – Check If Value Exists

Returns true or false.



 4. find() – Returns First Matching Value

Used for searching based on a condition.


 


 5. findIndex() – Returns Index of First Match



 6. search() Using some() (Check Condition)

Returns true if at least one element matches.



 7. every() – Check if All Elements Match Condition



Summary Table

Method Returns Purpose
indexOf() Index or -1 Search exact value
lastIndexOf() Index or -1 Last match search
includes() true / false Check if exists
find() Value First match based on condition
findIndex() Index First match index based on condition
some() true / false At least one matches
every() true / false All must match

Example Combined Search


 

You may also like...