JavaScript Array keys()

Definition and Usage

keys() The method returns an Array Iterator object with the array keys.

Note:keys() The method does not change the original array.

Example

Create an Array Iterator object that only contains the keys of the array, and then iterate over each key:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var fk = fruits.keys();
for (x of fk) {
  document.getElementById("demo").innerHTML += x + "<br>";
}

Try It Yourself

Syntax

array.keys()

Parameters

No parameters.

Technical Details

Return value: Array Iterator object
JavaScript Version: ECMAScript 6

Browser Support

The numbers in the table indicate the first browser version that fully supports this method.

Chrome Edge Firefox Safari Opera
Chrome 38 Edge 12 Firefox 28 Safari 8 Opera 25
October 2014 July 2015 March 2014 October 2014 October 2014

Note:Internet Explorer does not support keys() Methods.

Related Pages

Tutorial:JavaScript Array

Tutorial:JavaScript Array Const

Tutorial:JavaScript Array Methods

Tutorial:JavaScript Sorting Array

Tutorial:JavaScript Array Iteration