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.
-Function1.png)
<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>
So, we have an Array that has 5 names.
-Function2.png)
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