TypedArray.prototype.includes()
includes()
メソッドは、型付き配列が特定の要素を含んでいるかどうかを判断し、その結果に応じて true
か false
を返します。このメソッドは Array.prototype.includes()
と同じアルゴリズムです。 TypedArray は、ここでは 型付き配列型のうちの一つです。
試してみましょう
構文
typedarray.includes(searchElement[, fromIndex]);
引数
searchElement
-
探す対象の要素
fromIndex
-
オプション。
searchElement
を探し始める配列内の位置。既定では 0 です。
返値
Boolean
です。
例
includes の使用
var uint8 = new Uint8Array([1,2,3]);
uint8.includes(2); // true
uint8.includes(4); // false
uint8.includes(3, 3); // false
// NaN の扱い (Float32 および Float64 に限り true)
new Uint8Array([NaN]).includes(NaN); // false (コンストラクターに渡した NaN は 0 に変換されるため)
new Float32Array([NaN]).includes(NaN); // true;
new Float64Array([NaN]).includes(NaN); // true;
仕様書
Specification |
---|
ECMAScript Language Specification # sec-%typedarray%.prototype.includes |
ブラウザーの互換性
BCD tables only load in the browser