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

Zobacz r贸wnie偶