How to use JavaScript Object keys()

Program to use JavaScript Object keys() method


let player = {
    name: "Cristiano Ronaldo",
    age: "38",
    game: "football",

};

let a = Object.keys(player);
console.log(a);

Output


[ 'name', 'age', 'game' ]

Steps Description

  1. Declare two variable Object variable and variable player and a
  2. Initialize two variable Object variable and variable player and a with value of Object player = {name: "Cristiano Ronaldo",age: "38",game: "football",}; and a
  3. The Object key() method outputs the given object into an array.
  4. The value of a variable is displayed with the help of console.log inbuilt function