JavaScript Interview Question #32
What is Object.keys()?
Objects, Arrays & Core Data Handling Junior Beginner
Quick Interview Answer
Object.keys returns an array containing the object's own enumerable string-keyed property names. It does not include inherited properties or symbol keys.
Detailed Explanation
Object.keys returns an array containing the object's own enumerable string-keyed property names. It does not include inherited properties or symbol keys.
It is useful when iterating through property names, counting enumerable own properties, or transforming an object.
Code Example
const user = {
id: 1,
name: "Asif",
city: "Multan"
};
const keys = Object.keys(user);
console.log(keys);
// ["id", "name", "city"]