--- title: Array.prototype.keys() slug: Web/JavaScript/Reference/Global_Objects/Array/keys tags: - ECMAScript 2015 - JavaScript - Method - Prototype - Довідка - Масив translation_of: Web/JavaScript/Reference/Global_Objects/Array/keys ---
Метод keys()
вертає новий об'єкт перебирача ключів (індексів) масиву.
{{EmbedInteractiveExample("pages/js/array-keys.html")}}
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()
Новий об'єкт перебирача {{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]
Специфікація | Статус | Коментар |
---|---|---|
{{SpecName('ES2015', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ES2015')}} | Початкова виознака. |
{{SpecName('ESDraft', '#sec-array.prototype.keys', 'Array.prototype.keys')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Array.keys")}}