Objects - methods Flashcards
1
Q
Object.keys(obj): This method returns an array of the own enumerable property names of obj.
A
let obj = { name: ‘John’, age: 30 };
let keys = Object.keys(obj);
console.log(keys); // outputs [‘name’, ‘age’]
2
Q
Object.values(obj): This method returns an array of the own enumerable property values of obj.
A
let obj = { name: ‘John’, age: 30 };
let values = Object.values(obj);
console.log(values); // outputs [‘John’, 30]
3
Q
Object.entries(obj)
A
let obj = { name: ‘John’, age: 30 };
let entries = Object.entries(obj);
console.log(entries); // outputs [[‘name’, ‘John’], [‘age’, 30]]