English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
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.
The numbers in the table specify the first browser version that fully supports the find() method:
Method | |||||
find() | 45 | 25 | 32 | 8 | 12 |
Parameter | Description |
---|---|
callback | A function that is run for each element in the array. Function Parameters:
|
thisArg | (Optional) ExecuteCallbackUsed asthisObject The value passed to the function is generally the 'this' value. |
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 |