Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. TypedArray
  6. includes()

TypedArray.prototype.includes()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨September 2016⁩.

Theincludes() method ofTypedArray instances determines whether a typed array includes a certain value among its entries, returningtrue orfalse as appropriate. This method has the same algorithm asArray.prototype.includes().

Try it

const uint8 = new Uint8Array([10, 20, 30, 40, 50]);console.log(uint8.includes(20));// Expected output: true// Check from position 3console.log(uint8.includes(20, 3));// Expected output: false

Syntax

js
includes(searchElement)includes(searchElement, fromIndex)

Parameters

searchElement

The value to search for.

fromIndexOptional

Zero-based index at which to start searching,converted to an integer.

Return value

A boolean value which istrue if the valuesearchElement is found within the typed array (or the part of the typed array indicated by the indexfromIndex, if specified).

Description

SeeArray.prototype.includes() for more details. This method is not generic and can only be called on typed array instances.

Examples

Using includes()

js
const uint8 = new Uint8Array([1, 2, 3]);uint8.includes(2); // trueuint8.includes(4); // falseuint8.includes(3, 3); // false// NaN handling (only relevant for floating point arrays)new Uint8Array([NaN]).includes(NaN); // false, since the NaN passed to the constructor gets converted to 0new Float32Array([NaN]).includes(NaN); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-%typedarray%.prototype.includes

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp