2

How to destruct a value from array?

const ?? = { text: ['some text'] };
1
  • General advice for destructuring. If you're not sure how to destructure a particular value from an object literal, make the destructuring syntax match the object literal. Though in this case, the assignment might be much easier to read as const someText = object.text[0] instead. Commented May 7, 2019 at 21:40

1 Answer 1

7

const { text: [someText]} = { text: ['some text'] };

console.log(someText);

Sign up to request clarification or add additional context in comments.

Comments