By Hemanta Sundaray on 2021-07-02
Returns an array whose elements are strings corresponding to the enumerable properties of the object.
const person = {
firstName: "Hemanta",
lastName: "Sundaray",
occupation: "developer",
location: "New Delhi",
}
console.log(Object.keys(person))
// [ 'firstName', 'lastName', 'occupation', 'location' ]
Returns an array whose elements are the enumerable property values found on the object.
const person = {
firstName: "Hemanta",
lastName: "Sundaray",
occupation: "developer",
location: "New Delhi",
}
console.log(Object.values(person))
// [ 'Hemanta', 'Sundaray', 'developer', 'New Delhi' ]
Returns an array whose elements are arrays corresponding to the enumerable [key, value] pairs found on the object.
const person = {
firstName: "Hemanta",
lastName: "Sundaray",
occupation: "developer",
location: "New Delhi",
}
console.log(Object.entries(person))
// [
// [ 'firstName', 'Hemanta' ],
// [ 'lastName', 'Sundaray' ],
// [ 'occupation', 'developer' ],
// [ 'location', 'New Delhi' ]
// ]