How to use JavaScript Array keys()

Array keys()

On this page

Array keys() method

Program to use JavaScript Array keys() method

let a = ["JavaScript","Python","Php","Css","Html"];
    let b = a.keys();
    
    for(let key of b){
        console.log(key);
    }
    

Output

    0
    1
    2
    3
    4
    

Steps Description

  • Declare three variable a, b and key
  • Initialize three variable with value of array a = [“JavaScript”,”Python”,”Php”,”Css”,”Html”], b = a.keys() and key
  • Array keys() method returns the index number of the given array.
  • The value of key variable is displayed with the help of console.log inbuilt function