Метод keys()
вертає новий об'єкт перебирача ключів (індексів) масиву.
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]
Специфікації
Специфікація | Статус | Коментар |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.keys' in that specification. |
Standard | Початкова виознака. |
ECMAScript (ECMA-262) The definition of 'Array.prototype.keys' in that specification. |
Living Standard |
Підтримка веб-переглядачами
BCD tables only load in the browser
Таблиця сумісності на цій сторінці створена зі структурованих даних. Якщо ви хочете долучитися до розробки цих даних, пропонуйте нам свої pull request до репозиторію https://github.com/mdn/browser-compat-data.