JavaScript Object.keys() Method Example

The Object.keys() method returns an array of a given object's own property names, in the same order as we get with a normal loop.

Object.keys() Method Example

var user = {
    firstName: 'Ramesh',
    lastName: 'Fadatare',
    emailId: 'ramesh@gmail.com',
    age: 29
}

const keys = Object.keys(user)
console.log(keys) // [apple, orange, pear]
for (const key of keys) {
    console.log(" key :: " + key);
    console.log(" value :: " + user[key]);
}
Output:
key :: firstName
value :: Ramesh
key :: lastName
value :: Fadatare
key :: emailId
value :: ramesh@gmail.com
key :: age
value :: 29

Read more in the below tutorial



Comments