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

MethodReturnsPurpose
indexOf()Index or -1Search exact value
lastIndexOf()Index or -1Last match search
includes()true / falseCheck if exists
find()ValueFirst match based on condition
findIndex()IndexFirst match index based on condition
some()true / falseAt least one matches
every()true / falseAll must match

Example Combined Search


 

You may also like...