JavaScript Array find() Method

Learn via video course
FREE
View all courses
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
JavaScript Course With Certification: Unlocking the Power of JavaScript
JavaScript Course With Certification: Unlocking the Power of JavaScript
by Mrinal Bhattacharya
1000
4.8
Start Learning
Topics Covered

The find method in JavaScript calls the function parameter for each index of the array. If the element satisfies the test function then the find method stops its execution and returns the element. Otherwise, if no element of the array satisfies the test function then the method returns undefined. Since the function is called for each index of the array, so the function will be called even for the unassigned values.

Syntax of array.find in javascript

Using Arrow Function

Transform Your Career

Choose from our industry-leading programs designed for career success

NSDC Certified

Modern Software and AI Engineering Program

Master full-stack development with AI integration

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Modern Data Science and ML with specialisation in AI

Advanced data science techniques with AI specialization

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

Advanced AIML with Specialisation in Agentic AI

Deep dive into AIML with focus on Agentic systems

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

DevOps, Cloud & AI Platform Engineering

Build and manage AI-powered cloud infrastructure

12 MonthsDuration
AI-LedCurriculum
Career SupportSupport
GoogleAmazonPaytm+1000 more
Go to Program
NSDC Certified

AI Engineering Advanced Certification by IIT-Roorkee

Premier AI engineering certification from IIT-Roorkee

3 MonthsDuration
AI-LedCurriculum
Career SupportSupport
Program highlights
Go to Program

Using Inline Function

Parameters of find method in javascript

Function: This is the function that will be executed for each index of the array. This function is executed with the following arguments,

Current Value: This is the current element of the Array.

Index: This is the index of the current element of the Array.

Arr: This is the array on which the find() method was called.

ThisValue: This object is used as this keyword inside the function parameter. This is an optional parameter and by default, it is set as undefined.

Return Value of array.find in javascript

Returns the first element that meets the provided test function. If no element meets the test function, undefined is returned by the find method in JavaScript.

Example

Let's have an example to find the first number in the array greater than 0.
Since we have to check whether the element is greater than 0, there is no need for the index and arr parameters.

Output:

find in JavaScript returns undefined if none of the Array elements meets the test function. Let's have an example for this case,

Output:

Note: The find in JavaScript does not alter the array, but the function passed can alter the array.

Turn Learning into Career Growth

1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary
1200+Hiring Partners
89%Placement Rate
11,000+Placements
147%Avg Salary Increment
2.5XCareer Growth
₹23 LPAAvg Post-Scaler Salary

More Examples

Find an Object in an Array by One of Its Properties

Let's have an example of finding an object in the array using one of its properties. Our array will store the student details, such as name and roll number, and we have to find the object with the given roll number.

Output:

Scaler Placement Report and Statistics

₹23L
AVG CTC
SCALER PLACEMENT PROOF

Scaler learners achieved 2.5x salary growth with average post-Scaler CTC reaching ₹23L.

11,000+placements
650+companies
Verified data

Find a Prime Number in an Array

Before moving to the program, let's see how we can check whether a number is prime. A prime number is a number that is divisible by 1 and the number itself; hence, we will loop over the numbers [2,element-1], and if any of the numbers in the range completely divide the element, we will return false.

Output:

Conclusion

  • The find in JavaScript returns the first element in the specified array that meets the testing condition.
  • If no element meets the test function undefined is returned by find in JavaScript.
  • find method in JavaScript accepts 5 parameters, function, currentValue, index, arr, thisValue.
  • The find in JavaScript does not alter the array, but the function passed can alter the array.

See Also

Hiring Partners:
GoogleGoogleAmazonAmazonMicrosoftMicrosoftFlipkartFlipkartAdobeAdobe1200+ more