Is there any way to destructure an object and assign its properties into an array rather than as variables? For example:
const obj = { a: 1, b: 2 };
const { a, b } = obj;
const arr = [a, b];
This works, but it requires restating the variables as the array values.
I have tried:
const arr = [(const { a, b } = obj)];
but this is a syntax error.
I had a similar idea with Object.values
as in
const arr = Object.values((const { red } = chalk));`
...but this has the same issue of not being able to do destructuring in expressions.