user67867
user67867

Reputation: 421

access arrays inside an object

I have an object structure as given below. I had grouped like this using underscore js based on the id values

  {
      "1": [
        {
          "id": 1,
          "tailName": "ABQ-PHX",
          "itemId": 1,
          "name": "a1",
          "start": "24-11-2013,2:38",
          "end": "29-11-2013,18:22"
        },
        {
          "id": 1,
          "tailName": "ABQ-PHX",
          "itemId": 9,
          "name": "a2",
          "start": "16-12-2013,10:46",
          "end": "18-12-2013,10:46"
        }
      ],
      "2": [
        {
          "id": 2,
          "tailName": "BNA-RDU",
          "itemId": 14,
          "name": "b1",
          "start": "21-11-2013,11:38",
          "end": "15-12-2013,7:52"
        }
      ]
    }

Please advise how to access the array from the above object.

I want to access the first array (i.e)

[
        {
          "id": 1,
          "tailName": "ABQ-PHX",
          "itemId": 1,
          "name": "a1",
          "start": "24-11-2013,2:38",
          "end": "29-11-2013,18:22"
        },
        {
          "id": 1,
          "tailName": "ABQ-PHX",
          "itemId": 9,
          "name": "a2",
          "start": "16-12-2013,10:46",
          "end": "18-12-2013,10:46"
        }
      ]

Upvotes: 1

Views: 56

Answers (1)

xdazz
xdazz

Reputation: 160833

Both your_object[1] and your_object["1"] will give you the result.

Upvotes: 2

Related Questions