JavaScript | Array.find() Method

Introduction:
The Array.find() is an inbuilt function in JavaScript which is used to get the value of the first element in the array that satisfies the provided condition.It checks all the elements of the array and whichever the first element satisfies the condition is going to print.
Syntax:

array.find(function(element))

Parameters:
element:
– It is the element of the array on which array.find() function works.
Return value:
It return returns the array element value if any of the elements in the array which satisfy the condition, otherwise it returns undefined.
Browser Support:
Here 2nd column contain int values that are version of the corresponding browser.

Feature Basic support
Chrome 45
Edge Yes
Firefox 25
Internet Explorer No
Opera 32
Safari 8
Android webview Yes
Chrome for Android Yes
Edge mobile Yes
Firefox for Android 4
Opera Android Yes
iOS Safari 8

Examples:
Here the Array.find() method in JavaScript returns the value of the first element in the array that satisfies the provided testing function.
Let\’s see JavaScript program:

filter_none

edit
close

play_arrow

link
brightness_4
code

// input array contain some elements.
var array = [10, 20, 30, 40, 50];
  
// Here find function returns the value of the first element
// in the array that satisfies the provided testing
// function (return element > 10).
var found = array.find(function(element) {
  return element > 20;
});
  
// Printing desired values.
console.log(found);

chevron_right


Output:

> 30

Application:
Whenever we need to get the value of the first element in the array that satisfies the provided testing function that time we use Array.find() method in JavaScript.
Let\’s see JavaScript program:

filter_none

edit
close

play_arrow

link
brightness_4
code

// input array contain some elements.
var array = [2, 7, 8, 9];
  
// Here find function returns the value of 
// the first element in the array that satisfies 
// the provided testing function (return element > 4).
var found = array.find(function(element) {
  return element > 4;
});
  
// Printing desired values.
console.log(found);

chevron_right


Output:

> 7


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.