Home >>JavaScript Array Reference >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()
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
keys() | 38.0 | 12.0 | 28.0 | 8 | 25.0 |
<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>
<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>