2013-12-17 94 views
1

我有一個對象結構如下所示。我喜歡分組根據id此使用下劃線JS值訪問對象內的數組

{ 
     "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" 
     } 
     ] 
    } 

請告知如何從上述對象訪問陣列。

我要訪問的第一陣列(即)

[ 
     { 
      "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

兩個your_object[1]your_object["1"]會給你的結果。