Question Bank

JavaScript Object Values to Array: Two Approaches Quiz

Difficulty: Medium

Two seeded approaches to convert an object's values to an array (Object.values spread vs Object.keys.map) plus two companions on Object.entries and ordering pitfalls.

Question Bank
/

JavaScript Object Values to Array: Two Approaches Quiz

JavaScript Object Values to Array: Two Approaches Quiz

Two seeded approaches to convert an object's values to an array (Object.values spread vs Object.keys.map) plus two companions on Object.entries and ordering pitfalls.

Question Bank
Medium
JavaScript
4 questions
quiz
references
arrays
fundamentals

1,026 views

27

Implement toArray(obj) to return an array of the object's own enumerable values, using Object.values and the spread operator. Why is the spread harmless here?

Examples

Example 1:

Input: { a: 1, b: 2, c: 3 }
Output: [1, 2, 3]
Explanation: `Object.values` already returns an array; the spread copies it into a new array literal.