Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




keys() - FUNCTION


keys() Function is used to return the keys from an Array .


Let us say, we have a Array that contains five names, Mohan, Kriti, Philip, Salim and Andrew. And we want to get the index for the values.

JavaScript keys()-Function

Example :



<html>
<body>  
<script>

	var x = ["Mohan", "Kriti", "Philip", "Salim", "Andrew"]
	var y = x.keys()
	
	for(i of y) {
		document.write(i, "</br>")
	}    
    
</script>      
</body>
</html>


Output :



  0
  1
  2
  3
  4

So, we have an Array that has 5 names.

JavaScript keys()-Function

In the above Array, the indexes are the Keys and its actual values are the values. And keys() function extracts keys or indexes.


var y = x.keys()

Now, if you see the output, you get the keys.


0
1
2
3
4