TypedArray.prototype.keys()

keys() メソッドは、配列内の各添字に対するキーを含む新しい配列イテレーターオブジェクトを返します。

試してみましょう

構文

keys()

返値

新しい配列イテレーターオブジェクトです。

for...of を使用した反復処理

const arr = new Uint8Array([10, 20, 30, 40, 50]);
const arrKeys = arr.keys();
for (const n of arrKeys) {
  console.log(n);
}

他の繰り返し処理

const arr = new Uint8Array([10, 20, 30, 40, 50]);
const arrKeys = arr.keys();
console.log(arrKeys.next().value); // 0
console.log(arrKeys.next().value); // 1
console.log(arrKeys.next().value); // 2
console.log(arrKeys.next().value); // 3
console.log(arrKeys.next().value); // 4

仕様書

Specification
ECMAScript Language Specification
# sec-%typedarray%.prototype.keys

ブラウザーの互換性

BCD tables only load in the browser

関連情報