Home JavaScript TypedArray Methods includes() JavaScript TypedArray includes() Method Definition typedArray.includes(value) checks whether the typed array contains the value and returns true or false. It compares with strict equality, so no type conversion happens: the string "2" is not the number 2. One special rule: it can find NaN in a Float32Array or Float64Array, which indexOf() cannot. An optional second argument sets where the search starts.
typedArray.includes(value)
typedArray.includes(value, fromIndex)
new Uint8Array([4, 8, 15]).includes(8) → true
new Uint8Array([4, 8, 15]).includes(9) → false
new Float32Array([NaN]).includes(NaN) → true
new Float32Array([NaN]).indexOf(NaN) → -1 Syntax includes() takes the value to look for and an optional start position.
typedArray.includes(searchElement)
typedArray.includes(searchElement, fromIndex) Call What it does ta.includes(15)Is 15 anywhere in the typed array? Answer: true or false. ta.includes(4, 1)Search only from index 1 to the end. ta.includes(42, -1)A negative start counts from the end: search only the last element.
Built into JavaScript on all 11 typed array types. Unlike indexOf(), it treats NaN as equal to NaN, and it also treats 0 and -0 as equal.
Library declarations TypedArray.prototype.includes(searchElement, fromIndex)
// strict equality, except NaN equals NaN
// fromIndex < 0 -> start at length + fromIndex (not below 0)
// returns true or false Parameters Parameter Description searchElement The value to look for. It is not converted: a string never matches a number, and 1.5 is not converted to 1 for an Int8Array. fromIndex Optional. The index to start from. Negative values count from the end. The default is 0.
Return Value Return Value Description Boolean true if the value was found at or after fromIndex, otherwise false. The regular-array version is Array includes() .
Important
The value you search for is compared as it is, but the elements were already converted when they were stored. A Float32Array holding 0.1 really holds 0.10000000149011612, so includes(0.1) is false. Search with Math.fround(0.1) instead.
JavaScript Examples 1. Contains and fromIndex 2. Finding NaN 3. No type conversion Example 1 — Is This Code Allowed? Six allowed codes are stored in a Uint8Array. includes() answers with a boolean, and fromIndex narrows the search.
const allowed = new Uint8Array([4, 8, 15, 16, 23, 42]);
console.log(allowed.includes(15)); // true
console.log(allowed.includes(99)); // false
console.log(allowed.includes(4, 1)); // false
console.log(allowed.includes(42, -1)); // true
console.log(allowed.includes(4, -6)); // true true
false
false
true
true How It Works Yes or no. 15 is in the list, 99 is not. The answer is only a boolean, never the position.Starting later hides early values. The only 4 sits at index 0, so includes(4, 1), which starts at index 1, cannot see it.Negative starts count from the end. -1 means start at index 5, which holds 42. -6 means start at index 0, so 4 is found again.Example 2 — includes() Finds NaN, indexOf() Does Not A Float32Array can store NaN for a missing measurement. The two search methods disagree about it.
const readings = new Float32Array([1.5, NaN, 3]);
console.log(readings.includes(NaN)); // true
console.log(readings.indexOf(NaN)); // -1
console.log(new Float64Array([NaN]).includes(NaN)); // true
const whole = new Int16Array([NaN]);
console.log(whole.join(',')); // 0
console.log(whole.includes(NaN)); // false
console.log(whole.includes(0)); // true true
-1
true
0
false
true How It Works NaN equals NaN here. includes() uses a comparison that treats two NaN values as the same, so it reports true.indexOf() cannot match NaN. It uses strict equality, where NaN === NaN is false, so it gives -1 even though the value is stored.Integers turn NaN into 0. An Int16Array has no way to hold NaN, so it stored 0. Searching for NaN fails, and searching for 0 succeeds.Example 3 — Why 1.5 Is Not in an Int8Array Searching never converts the value you pass. The stored elements, however, were converted when they were written.
const small = new Int8Array([1, 2, 3]);
console.log(small.includes(1.5)); // false
console.log(small.includes('2')); // false
console.log(small.includes(2)); // true
const stored = new Int8Array([1.5]);
console.log(stored.join(',')); // 1
console.log(stored.includes(1.5)); // false
console.log(stored.includes(1)); // true
const f = new Float32Array([0.1]);
console.log(f.includes(0.1)); // false
console.log(f.includes(Math.fround(0.1))); // true false
false
true
1
false
true
false
true How It Works Only exact values match. The numbers 1, 2, 3 are stored, so 1.5 and the string "2" find nothing, while the number 2 does.The stored value was cut. Writing 1.5 into an Int8Array stores 1. Looking for 1.5 later still fails, but looking for 1 works.Single precision is the catch. The Float32 element is not exactly 0.1. Math.fround(0.1) rounds the search value the same way, so now they match.Compatibility
Browser & Runtime Support TypedArray.prototype.includes() works in every modern browser and runtime, just like Array.prototype.includes().
✓ Baseline
TypedArray.prototype.includes() Supported in every modern browser, plus Node.js, Deno, and Bun.
98% Modern browser support
Google Chrome All modern versions
Full support
Mozilla Firefox All modern versions
Full support
Apple Safari All modern versions
Full support
Microsoft Edge All modern versions
Full support
Node.js All current releases
Supported
Deno All releases
Supported
Internet Explorer IE 10 and 11 have typed arrays, but not this method
Not supported includes() Excellent
Bottom line: Safe everywhere modern JavaScript runs. Only Internet Explorer is missing it: IE 10 and 11 have typed arrays, but not this method.
Frequently Asked Questions What does TypedArray includes() return? It returns true if the value is in the typed array and false if it is not. It never returns an index.
Why can includes() find NaN but indexOf() cannot? includes() treats NaN as equal to NaN. indexOf() uses strict equality, and NaN === NaN is false in JavaScript.
Why does includes(0.1) fail on a Float32Array holding 0.1? The array stores the nearest single-precision number, 0.10000000149011612, not 0.1. Search with Math.fround(0.1) instead.
Does includes() convert the search value? No. It uses strict comparison. includes("2") does not find the number 2, and includes(1.5) does not find 1 in an Int8Array.
What does a negative fromIndex do? It counts from the end. With length 6, a fromIndex of -2 starts at index 4.
About the author Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
11 people found this page helpful
Helpful Share Copy link Suggestion