Typed Array findIndex()
Example
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// The index of the first element with a value over 18
let result = myArr.findIndex(x => x > 18);
Try it Yourself »
Description
The findIndex()
method returns the index (position) of the first element that passes a test.
The findIndex()
method executes a function for each array element.
The findIndex()
method returns -1 if no match is found.
The findIndex()
method does not execute the function for empty array elements.
The findIndex()
method does not change the original array.
Syntax
typed-array.findIndex(function(currentValue, index, arr), thisValue)
typed-array must be one of the following: Int8ArrayUint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float16Array Float32Array Float64Array BigInt64Array BigUint64Array |
Parameters
Parameter | Description |
function() | Required. A function to be run for each array element. |
currentValue | Required. The value of the current element. |
index | Optional. The index of the current element. |
arr | Optional. The array of the current element. |
thisValue | Optional. Default undefined .A value passed to the function as its this value. |
Return Value
Type | Description |
Number |
The index of the first element that passes the test. Otherwise -1. |
Typed Array Find Methods:
Method | Finds |
---|---|
includes() | Returns true if an element is present in the array |
indexOf() | The index of the first element with a specified value |
lastIndexOf() | The index of the last element with a specified value |
find() | The value of the first element that passes a test |
findIndex() | The index of the first element that passes a test |
findLast() | The value of the last element that passes a test |
findLastIndex() | The index of the last element that passes a test |
JavaScript Typed Arrays
Browser Support
typed-array.findIndex()
is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is fully supported in all modern browsers since June 2017:
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |