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’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly