Typed Array includes()
Examples
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// Search for an element with a value of 20
let result = myArr.indexOf(20);
Try it Yourself »
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30,35,40,45,50]);
// Search for an element with a value of 20
let result = myArr.indexOf(20, 3);
Try it Yourself »
Description
The includes()
method returns true
if a typed array contains a specified value.
The includes()
method returns false
if the value is not found.
The includes()
method is case sensitive.
Syntax
typed-array.includes(element, start)
typed-array must be one of the following: Int8ArrayUint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float16Array Float32Array Float64Array BigInt64Array BigUint64Array |
Parameters
Parameter | Description |
element | Required. The value to search for. |
start | Optional. Start position. Default is 0. |
Return Value
Type | Description |
A boolean |
true if the value is found, otherwise false . |
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.includes()
is an ECMAScript7 (ES7) feature.
JavaScript 2016 is supported in all modern browsers:
Chrome | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes |