JavaScript TypedArray includes() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
ES2016

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.

Remember
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.

JavaScript
typedArray.includes(searchElement)
typedArray.includes(searchElement, fromIndex)
CallWhat 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
JavaScript
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

ParameterDescription
searchElementThe 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.
fromIndexOptional. The index to start from. Negative values count from the end. The default is 0.

Return Value

Return ValueDescription
Booleantrue if the value was found at or after fromIndex, otherwise false. The regular-array version is Array includes().

JavaScript Examples

Example 1 — Is This Code Allowed?

Six allowed codes are stored in a Uint8Array. includes() answers with a boolean, and fromIndex narrows the search.

JavaScript
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
Try It Yourself

How It Works

  1. Yes or no. 15 is in the list, 99 is not. The answer is only a boolean, never the position.
  2. Starting later hides early values. The only 4 sits at index 0, so includes(4, 1), which starts at index 1, cannot see it.
  3. 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.

JavaScript
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
Try It Yourself

How It Works

  1. NaN equals NaN here. includes() uses a comparison that treats two NaN values as the same, so it reports true.
  2. indexOf() cannot match NaN. It uses strict equality, where NaN === NaN is false, so it gives -1 even though the value is stored.
  3. 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.

JavaScript
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
Try It Yourself

How It Works

  1. 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.
  2. 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.
  3. 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.

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

It returns true if the value is in the typed array and false if it is not. It never returns an index.
includes() treats NaN as equal to NaN. indexOf() uses strict equality, and NaN === NaN is false in JavaScript.
The array stores the nearest single-precision number, 0.10000000149011612, not 0.1. Search with Math.fround(0.1) instead.
No. It uses strict comparison. includes("2") does not find the number 2, and includes(1.5) does not find 1 in an Int8Array.
It counts from the end. With length 6, a fromIndex of -2 starts at index 4.

Next: indexOf()

Find the first position of an exact value in the typed array.

indexOf() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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