indexOf()
method returns the first index at which a given element can be found in the typed array, or -1 if it is not present. This method has the same algorithm as
Array.prototype.indexOf()
.
TypedArray
is one of the
typed array types
here.
typedarray.indexOf(searchElement[, fromIndex = 0])
searchElement
Element to locate in the typed array.
fromIndex
The index to start the search at. If the index is greater than or equal to the typed array's length, -1 is returned, which means the typed array will not be searched. If the provided index value is a negative number, it is taken as the offset from the end of the typed array. Note: if the provided index is negative, the typed array is still searched from front to back. If the calculated index is less than 0, then the whole typed array will be searched. Default: 0 (entire typed array is searched).
The first index of the element in the array;
-1
若找不到。
indexOf
compares
searchElement
to elements of the typed array using
strict equality
(the same method used by the ===, or triple-equals, operator).
var uint8 = new Uint8Array([2, 5, 9]); uint8.indexOf(2); // 0 uint8.indexOf(7); // -1 uint8.indexOf(9, 2); // 2 uint8.indexOf(2, -1); // -1 uint8.indexOf(2, -3); // 0
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'TypedArray.prototype.indexOf' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
indexOf
|
Chrome 45 | Edge 14 |
Firefox
37
|
IE No | Opera 32 | Safari No | WebView Android No | Chrome Android 45 |
Firefox Android
37
|
Opera Android 32 | Safari iOS No | Samsung Internet Android 5.0 | nodejs 4.0.0 |
完整支持
不支持
见实现注意事项。
TypedArray
TypedArray.from()
TypedArray.of()
TypedArray.prototype.copyWithin()
TypedArray.prototype.entries()
TypedArray.prototype.every()
TypedArray.prototype.fill()
TypedArray.prototype.filter()
TypedArray.prototype.find()
TypedArray.prototype.findIndex()
TypedArray.prototype.forEach()
TypedArray.prototype.includes()
TypedArray.prototype.indexOf()
TypedArray.prototype.join()
TypedArray.prototype.keys()
TypedArray.prototype.lastIndexOf()
TypedArray.prototype.map()
TypedArray.prototype.reduce()
TypedArray.prototype.reduceRight()
TypedArray.prototype.reverse()
TypedArray.prototype.set()
TypedArray.prototype.slice()
TypedArray.prototype.some()
TypedArray.prototype.sort()
TypedArray.prototype.subarray()
TypedArray.prototype.toLocaleString()
TypedArray.prototype.toString()
TypedArray.prototype.values()
TypedArray.prototype[@@iterator]()
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()