TypedArray.prototype.includes()
The includes()
method determines whether a typed array includes a certain element, returning true
or false
as appropriate. This method has the same algorithm as Array.prototype.includes()
. TypedArray is one of the typed array types here.
Syntax
includes(searchElement) includes(searchElement, fromIndex)
Parameters
searchElement
-
The element to search for.
-
fromIndex
Optional -
The position in this array at which to begin searching for
searchElement
; defaults to 0.
Return value
A Boolean
.
Examples
Using includes
var uint8 = new Uint8Array([1,2,3]); uint8.includes(2); // true uint8.includes(4); // false uint8.includes(3, 3); // false // NaN handling (only true for Float32 and Float64) new Uint8Array([NaN]).includes(NaN); // false, since the NaN passed to the constructor gets converted to 0 new Float32Array([NaN]).includes(NaN); // true; new Float64Array([NaN]).includes(NaN); // true;
Specifications
Browser compatibility
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
includes |
47 |
14 |
43 |
No |
34 |
10 |
No |
47 |
43 |
34 |
10 |
5.0 |
See also
- A polyfill of
TypedArray.prototype.includes
is available incore-js
Array.prototype.includes()
String.prototype.includes()
TypedArray.prototype.indexOf()
© 2005–2021 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/includes