Is it possible to destructure an object directly into an array?

Let’s say I have an object such as

const myObj = { "type":"candy", "brand":"mars bars"}

If I would like to make an array with the variables type and brand like

const arr = [type, brand]

Is there any way to directly destructure the variables so they go into the array or do I need to add them in separately?

you can use Object.keys() to get the keys of an object

Object.entries() gives you exactly what you want:

1 Like