-1

Say I have an object with a shape like so:

{
  rows: [
    {some: fields,
     go: here}]
}

, and say that, in a particular case, I knew that the length of rows is 1. How could I extract {some: fields, go: here} through destructuring?

I have attempted: {rows: [stuff]}, and {rows: stuff} but in both cases console.log(stuff) prints [{some: fields, go: here}] How can I do this through destructuring?

Abraham P
  • 15,029
  • 13
  • 58
  • 126

1 Answers1

0

{rows: [stuff]} works fine:

const obj = {
  rows: [
    {some: 'fields',
     go: 'here'}]
};

const { rows: [stuff] } = obj;
console.log(stuff);
Michał Perłakowski
  • 88,409
  • 26
  • 156
  • 177
  • 2
    Why are you getting all of these downvotes? I think your answer works just fine according to my reading. It's super annoying when people downvote answers just because they downvote the question because they think it's a duplicate. – samanime Jun 20 '17 at 18:48