JavaScript | array.keys()
The array.keys() is an inbuilt function in JavaScript which is used to return a new array iterator which contains the keys for each index in the given input array.
Syntax:
array.keys()
Parameter: It doesn’t take any parameter.
Return Values: It returns a new array iterator.
Code #1:
<script> // Taking input as an array A // containing some elements. var A = [ 'gfg', 'geeks', 'cse', 'geekpro' ]; // array.keys() function is called var iterator = A.keys(); // printing index array using the iterator for (let key of iterator) { document.write(key + ' '); } </script> |
chevron_right
filter_none
Output:
0 1 2 3
Code #2:
<script> // Taking input as an array A // containing some elements var A = [ 'gfg', 'geeks', 'cse', 'geekpro', '', 1, 2 ]; // array.keys() function is called var iterator = A.keys(); // printing index array using the iterator for (let key of iterator) { document.write(key + ' '); } </script> |
chevron_right
filter_none
Output:
0 1 2 3 4 5 6
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- JavaScript Course | What is JavaScript ?
- JavaScript | Let
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



