English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array find() Method

 JavaScript Array Object

The find() method returns the value of the first element in the array that satisfies the provided test function.

The find() method executes the callback function once for each array index:

  • if the function returnstruethe array element with the valuefind()immediately return the value of the found element

  • otherwise, it returnsundefinedindicates that no elements pass the test

Note: The find() method does not change the original array.

Syntax:

array.find(callback, thisArg)
var num = [1, 30, 39, 29, 10, 13];
var val = num.find(myFunc);
function myFunc(element) {
return element >= 18;
}
Test and see‹/›

Please see alsofindIndex()Method that returns the index of the element found in the array instead of its value.

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the find() method:

Method
find()452532812

Parameter Value

ParameterDescription
callback
A function that is run for each element in the array.
Function Parameters:
  • element(Required)-The current element being processed in the array

  • index(Optional)-The index of the current element being processed in the array

  • array(Optional)- The array object that belongs to the current element

thisArg

(Optional) ExecuteCallbackUsed asthisObject

The value passed to the function is generally the 'this' value.
If this parameter is empty, 'undefined' will be passed to the 'this' value

Technical Details

Return Value:Returns the value of the first array element that matches the test condition, or undefined if no such element is foundundefined
JavaScript Version:ECMAScript 6

 JavaScript Array Object