C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript TypedArray findIndex() MethodThe JavaScript findIndex() method provides the index of the first element in the array that completes the given test. If the test is not satisfied, it will return -1.
Syntax:array.findIndex(function(Value, index, arr) thisValue) Parameters:Value: The value of the current element. Index: The array index of the current element. Arr: The array object on which the findIndex() method operated. ThisValue: A value to be passed to the function to be used as its "this" value. If the parameter is empty, the value "undefined" will be passed as its "this" value. Return value:Index of the array element, otherwise it returns -1. Browser Support:
Example 1JavaScript TypedArray findIndex() Method <script type="text/javascript"> // JavaScript to illustrate findIndex() method function JavaTpoint(value) { return value >34; } // Input array var arr = [1,2,3,4,5,6,7,8,9,12,11,14]; var result = arr.findIndex(JavaTpoint); document.write(result)// expected output: arr[Output:-1] </script> Output: -1 Example 2JavaScript TypedArray findIndex() Method <script type="text/javascript"> //JavaScript to illustrate findIndex() method function JavaTpoint(value) { return value ==6; } // Input array var arr = [1,2,3,4,5,6,7,8,9,12,11,14]; var result = arr.findIndex(JavaTpoint); document.write(result) // expected output: arr[Output:5] </script> Output: 5
Next TopicJavaScript TypedArray Object
|