JavaScript Array keys() Method
Example
Create an Array Iterator object, only containing the keys of the array, and then loop through 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 »
Definition and Usage
The keys()
method returns an Array Iterator object with the keys of an array.
Note: this method does not change the original array.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
keys() | 38.0 | 12.0 | 28.0 | 8 | 25.0 |
Syntax
array.keys()
Parameter Values
No parameters.
Technical Details
Return Value: | An Array Iterator object |
---|---|
JavaScript Version: | ECMAScript 6 |
Related Pages
JavaScript Tutorial: JavaScript Arrays
JavaScript Tutorial: JavaScript Array Iteration
❮ JavaScript Array Reference