0

My array is:

[
    {
        "_attributes": {
            "key": "attributes"
        },
        "dt_assoc": {
            "item": {
                "_attributes": {
                    "key": "status"
                },
                "_text": "taken"
            }
        }
    }
]

I have tried a couple of options but can't seem to get a specific object. Im trying to get; "dt_assoc":

{
            "item": {
                "_attributes": {
                    "key": "status"
                },
                "_text": "taken"
            };

2 Answers2

1

That's an array with only one item. Counting starts at zero. So to get to the item, you'd use array[0].

That will get you the object. That object has a property named dt_assoc. To access the property, you'd use array[0].dt_assoc.

rid
  • 61,078
  • 31
  • 152
  • 193
0

You access it by specifying index as 0 because it is an array.

const data = [{
  "_attributes": {
    "key": "attributes"
  },
  "dt_assoc": {
    "item": {
      "_attributes": {
        "key": "status"
      },
      "_text": "taken"
    }
  }
}]
console.log(data[0].dt_assoc)
holydragon
  • 6,158
  • 6
  • 39
  • 62