Home >>JavaScript Array Reference >JavaScript Array keys() Method

JavaScript Array keys() Method

JavaScript Array keys() Method

JavaScript array keys() method in JavaScript is used to returns and creates a new Array Iterator objects with the keys of an array and does not affect the original array.

Syntax:
array.keys()

Browser Support

Method Chrome Edge Firefox Safari Opera
keys() 38.0 12.0 28.0 8 25.0
Here is an example of Array keys() method:
<html>
<body>
<p id="keys"></p>
<script>
var num = ["one", "Two", "Three", "Four"];
var funk = num.keys();
for (z of funk) 
{
  document.getElementById("keys").innerHTML += z + "<br>";
}
</script>
</body>
</html>
Output:

Example 2:
<html>
<body>
<button onclick="display()">Check Result</button>
<p id="numkey"></p>
<script>
  var NumArr = [5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 100];
  document.getElementById("numkey").innerHTML = NumArr;
  function display() {
  var res = NumArr.keys();
  for (val of res) 
  {
      document.getElementById("numkey").innerHTML += val + "<br>";
  }
  }
   </script>
</body>
</html>
Output:


No Sidebar ads