The indexOf()
method of TypedArray
instances 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()
.
The indexOf()
method of TypedArray
instances 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()
.
indexOf(searchElement) indexOf(searchElement, fromIndex)
searchElement
Element to locate in the typed array.
fromIndex
Optional
Zero-based index at which to start searching, converted to an integer.
The first index of searchElement
in the typed array; -1
if not found.
See Array.prototype.indexOf()
for more details. This method is not generic and can only be called on typed array instances.
const 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
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
indexOf |
45 | 12 | 37Starting with Firefox 47, this method will no longer return-0 . For example, new Uint8Array([0]).indexOf(0, -0) will now always return +0 . |
32 | 9.1 | 45 | 37Starting with Firefox 47, this method will no longer return-0 . For example, new Uint8Array([0]).indexOf(0, -0) will now always return +0 . |
32 | 9.3 | 5.0 | 45 | 1.0 | 4.0.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/indexOf