How can I destructure this array?

I just need the second object “data[0][1]” But I cannot deconstruct it
I been trying with:

let [a, b] = data
console.log(b) //  undefined

This is the array

const data = [
    [
        {
            "status": "rejected",
            "reason": {
                "name": "APIError",
                "errors": {
                    "assessment": [
                        "Assessment already exists"
                    ]
                },
                "statusCode": 422
            }
        },
        {
            "id": 5,
            "applicant": {
                "id": 5,
                "full_name": "Arturo Schamberger DDS",
            },
            "job": {
                "id": 17,
                "position": "Design Architect"
            },
            "date_submitted": "2022-08-02T14:16:02.080Z",
            "terms_and_conditions": {
                "title": "Terms And Condition for Design Architect",
                "description": [
                    {
                        "page_one": "Repellat voluptatem dolor. Quo aut consequuntur. Quia repudiandae ex."
                    },
                ]
            },
            "status": "Open - Shortlisted",
            "stage": "Open"
        }
    ]
]

What specifically does “doesn’t work” mean? What happens when you try that?

Your code is out of order - you should fix that first. You can’t destructure a variable that doesn’t exist yet!

I get undefined! I already fix the post.

Take a look at what is stored in a.

1 Like

It works, but I don’t get why doesn’t work with “b”

        {
            "status": "rejected",
            "reason": {
                "name": "APIError",
                "errors": {
                    "assessment": [
                        "Assessment already exists"
                    ]
                },
                "statusCode": 422
            }
        },

You cut out part of the output:

[ { status: 'rejected',
    reason: { name: 'APIError', errors: [Object], statusCode: 422 } },
  { id: 5,
    applicant: { id: 5, full_name: 'Arturo Schamberger DDS' },
    job: { id: 17, position: 'Design Architect' },
    date_submitted: '2022-08-02T14:16:02.080Z',
    terms_and_conditions: 
     { title: 'Terms And Condition for Design Architect',
       description: [Object] },
    status: 'Open - Shortlisted',
    stage: 'Open' } ]

See how a holds an array?

You right! thanks a lot

let [a] = data
let [z,x] = a
console.log(x) // works!
1 Like