C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray find() MethodThe JavaScript find() method is used to get the value of the first element in the array that satisfies the provided condition. The find() method apply the function once for each element present in the array. The function returns a true value, if it is found in the array and does not check the remaining value. Otherwise,it returns undefined.
Syntax:array.find(function(value, index, arr)) Parameters:Value (required): The value of the current element. Index (optional): The array index of the current element. Arr: The array object the current element belongs to. Return value:It returns the array element value if the elements in the array satisfy the condition, otherwise it returns undefined. Browser Support:
Example 1JavaScript Array find() Method <script type="text/javascript"> // JavaScript to illustrate find() method function JavaTpoint(value) { return value >12; } // Input array var arr = [1,2,3,4,5,6,7,8,9,12,11,14]; var result = arr.find(JavaTpoint); document.write(result) // expected output: arr[Output:14] </script> Output: 14 Example 2JavaScript Array find() Method <script type="text/javascript"> // JavaScript to illustrate find() method function JavaTpoint(value) { return value ==15; } // Input array var arr = [1,2,3,4,5,6,7,8,9,12,11,14]; var result = arr.find(JavaTpoint); document.write(result) // expected output: arr[Output: undefined] </script> Output: Undefined
Next TopicJavaScript TypedArray Object
|