Is there a way to destructure an object and assign its properties into an array instead of as variables? For instance:
const obj = { a: 1, b: 2 };
const { a, b } = obj;
const arr = [a, b];
The above method works fine, but it involves redefining the variables when creating the array.
I attempted to do this:
const arr = [(const { a, b } = obj)];
However, this results in a syntax error.
I also had a similar idea using Object.values
like so:
const arr = Object.values((const { red } = chalk));
...but encountered the same problem due to the inability to perform destructuring within expressions.