I have a JSON object (checked with typeof) and I am trying to access an array which is a property of my object. Issue I am having is that I can not get it to output anything when I to object.property

Here is my object, I am trying to access the users array inside this object. This object is assigned to a variable called policy when I do policy.users it gives undefined.

Is there something special about dealing with arrays inside objects I am missing?

{
    "_id": "5cb1fcc8fa3da31baf238bdb",
    "users": [
      "5c8d2a0c2f1f881e2377a601",
      "5cb14773c000525a8dfed406"
    ],
    "companyID": "62137607-0f1b-49a0-88e9-a2989447f4b2",
    "name": "My Policy",
    "createdAt": "2019-04-13T15:14:16.651Z",
    "__v": 0
  }

1 Answers

0
Syed Hammad Ahmed On Best Solutions

Judging by the object schema, I believe you are using mongodb (mongoose). If so you need to add the "users" property in the "policy" schema. Like this:

users: [{
  type: String
}]