--- title: Array.prototype.keys() slug: Web/JavaScript/Reference/Global_Objects/Array/keys translation_of: Web/JavaScript/Reference/Global_Objects/Array/keys original_slug: Web/JavaScript/Referencje/Obiekty/Array/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 }
arr.keys()
Nowy iterator dla typu {{jsxref("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]
Specyfikacja | Status | Komentarz |
---|---|---|
{{SpecName('ES2015', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ES2015')}} | Pierwsze wystąpienie. |
{{SpecName('ESDraft', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ESDraft')}} |
Feature | Chrome | Firefox (Gecko) | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatChrome("38")}} | {{CompatGeckoDesktop("28")}} | {{CompatVersionUnknown}} | {{CompatNo}} | {{CompatOpera("25")}} | {{CompatSafari("7.1")}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatNo}} | {{CompatGeckoMobile("28")}} | {{CompatNo}} | {{CompatNo}} | 8.0 |