← Back to challenges

Converting Objects to Arrays

JavaScriptHardarrayslanguage_fundamentalsobjects

Instructions

Write a function that converts an object into an array, where each element represents a key-value pair in the form of an array.

Examples

toArray({ a: 1, b: 2 }) ➞ [["a", 1], ["b", 2]]

toArray({ shrimp: 15, tots: 12 }) ➞ [["shrimp", 15], ["tots", 12]]

toArray({}) ➞ []

Notes

Return an empty array if the object is empty.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Concatenate Variable Number of Input Arrays