TypedArray.prototype.includes()
includes()
メソッドは、型付き配列が特定の要素を含んでいるかどうかを判断し、その結果に応じて true
か false
を返します。このメソッドは Array.prototype.includes()
と同じアルゴリズムです。 TypedArray は、ここでは 型付き配列型のうちの一つです。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
構文
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;
仕様書
ブラウザーの互換性
BCD tables only load in the browser