I have an array of values like:
const arr = [1,2,3];
Is there any way I can use destructuring to create the following output? If not, what
With destructuring, you can either create new variables or assign to existing variables/properties. You can't declare and reassign in the same statement, however.
const arr = [1, 2, 3], obj = {}; [obj.one, obj.two, obj.three] = arr; console.log(obj); // { one: 1, two: 2, three: 3 }