Array.prototype.keys()
Metoda keys()
zwraca nowy obiekt typu Array Iterator
zawierający indeksy kolejnych elementów tablicy.
var arr = ['a', 'b', 'c'];
var iterator = arr.keys();
console.log(iterator.next()); // { value: 0, done: false }
console.log(iterator.next()); // { value: 1, done: false }
console.log(iterator.next()); // { value: 2, done: false }
console.log(iterator.next()); // { value: undefined, done: true }
Składnia
arr.keys()
Zwracana wartość
Nowy iterator dla typu Array
.
Przykłady
Iterator nie ignoruje dziur
var arr = ['a', , 'c'];
var sparseKeys = Object.keys(arr);
var denseKeys = [...arr.keys()];
console.log(sparseKeys); // ['0', '2']
console.log(denseKeys); // [0, 1, 2]
Specyfikacje
Specyfikacja | Status | Komentarz |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.keys' in that specification. |
Standard | Pierwsze wystąpienie. |
ECMAScript (ECMA-262) The definition of 'Array.prototype.keys' in that specification. |
Living Standard |
Kompatybilność z przeglądarkami
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Feature | Chrome | Firefox (Gecko) | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | 38 | 28 (28) | (Yes) | No support | 25 | 7.1 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 28.0 (28) | No support | No support | 8.0 |