keys()
メソッドは、配列内の各インデックスのキーを含む、新しい Array Iterator オブジェクトを返します。
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.
構文
arr.keys()
返値
新しい Array
のイテレーターオブジェクトです。
例
疎な配列を無視しないキーイテレーター
var arr = ['a', , 'c'];
var sparseKeys = Object.keys(arr);
var denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys); // [0, 1, 2]
仕様書
ブラウザーの互換性
BCD tables only load in the browser