title: how do I fetch the second level array values in JSON data using jQuery each()
body: <p>I would like to select a particular value using jquery each from the second and third level array. This is my JSON response looks like:</p>
  
  <pre><code>{
      "events": [{
          "id": 847843,
          "name": "Strasbourg IG at Limoges CSP",
          "timezone": "GMT",
          "timezoneOffset": 0,
          "time": 1401983400000,
          "timeUtc": "2014-06-05T18:50:00+00:00",
          "status": "live",
          "wpRef": "847843",
          "parentCategoryId": 22,
          "parentCategoryName": "Basketball",
          "categoryId": 7443,
          "categoryName": "French Championnat Pro A ",
          "racingEvent": null,
          "raceNumber": null,
          "marketCount": 3,
          "prefix": null,
          "nameSeparator": null,
          "markets": [{
              "id": 4943131,
              "primitiveType": 2,
              "primitiveName": "Head to Head",
              "typeId": 36,
              "name": "Head to Head",
              "marketDescription": "Select the winner of the match.",
              "marketRules": "Includes extra time.\r",
              "eventNotices": null,
              "autoHide": false,
              "status": "live",
              "bettingStatus": "enabled",
              "period": "Fulltime",
              "allowMultiple": true,
              "betInRunTime": 0,
              "track": null,
              "weather": null,
              "betTypes": [{
                  "id": 1,
                  "name": "Win",
                  "finishingOrder": null,
                  "products": []
              }],
              "selections": [{
                  "id": 288481048,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Strasbourg IG",
                  "prefix": "",
                  "mpId": 288481048,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 2.6,
                      "usPrice": "+160",
                      "value": 2.60
                  }]
              }, {
                  "id": 288481039,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Limoges CSP",
                  "prefix": "",
                  "mpId": 288481039,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 1.44,
                      "usPrice": "-227",
                      "value": 1.44
                  }]
              }]
          }, {
              "id": 4943134,
              "primitiveType": 99,
              "primitiveName": "Other",
              "typeId": 1266,
              "name": "Odd or Even Total",
              "marketDescription": "Select whether the amount of points scored in the match will be an odd or even number (zero = even)\r\rIncludes overtime.",
              "marketRules": "For this market zero will be deemed to be an even number.\r\rNo bonus bets.\r\rIncludes overtime.",
              "eventNotices": null,
              "autoHide": true,
              "status": "live",
              "bettingStatus": "enabled",
              "period": "Fulltime",
              "allowMultiple": true,
              "betInRunTime": 0,
              "track": null,
              "weather": null,
              "betTypes": [{
                  "id": 1,
                  "name": "Win",
                  "finishingOrder": null,
                  "products": []
              }],
              "selections": [{
                  "id": 288481066,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Even",
                  "prefix": "",
                  "mpId": 288481066,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 1.85,
                      "usPrice": "-118",
                      "value": 1.85
                  }]
              }, {
                  "id": 288481075,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Odd",
                  "prefix": "",
                  "mpId": 288481075,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 1.85,
                      "usPrice": "-118",
                      "value": 1.85
                  }]
              }]
          }, {
              "id": 4943137,
              "primitiveType": 99,
              "primitiveName": "Other",
              "typeId": 1298,
              "name": "Match Result",
              "marketDescription": null,
              "marketRules": null,
              "eventNotices": null,
              "autoHide": false,
              "status": "live",
              "bettingStatus": "enabled",
              "period": "Fulltime",
              "allowMultiple": true,
              "betInRunTime": 0,
              "track": null,
              "weather": null,
              "betTypes": [{
                  "id": 1,
                  "name": "Win",
                  "finishingOrder": null,
                  "products": []
              }],
              "selections": [{
                  "id": 288481102,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Strasbourg IG",
                  "prefix": "",
                  "mpId": 288481102,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 2.63,
                      "usPrice": "+163",
                      "value": 2.63
                  }]
              }, {
                  "id": 288481084,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Limoges CSP",
                  "prefix": "",
                  "mpId": 288481084,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 1.5,
                      "usPrice": "-200",
                      "value": 1.50
                  }]
              }, {
                  "id": 288481093,
                  "betId": null,
                  "eventId": null,
                  "eventNumber": null,
                  "eventName": null,
                  "eventTime": null,
                  "position": null,
                  "name": "Draw",
                  "prefix": "",
                  "mpId": 288481093,
                  "marketPosition": null,
                  "marketName": null,
                  "marketTypeName": null,
                  "marketSelectionId": null,
                  "marketSelectionName": null,
                  "categoryId": null,
                  "categoryName": null,
                  "parentCategoryId": null,
                  "parentCategoryName": null,
                  "maxBet": 0.00,
                  "scratched": false,
                  "winPrice": null,
                  "placePrice": null,
                  "finalWinPrice": null,
                  "finalPlacePrice": null,
                  "finalPrice": null,
                  "prices": [{
                      "betTypeId": 1,
                      "betTypeName": "Win",
                      "productId": null,
                      "productName": null,
                      "precisePrice": 13.00,
                      "usPrice": "+1200",
                      "value": 13.00
                  }]
              }]
          }],
          "result": null
      }]
  }
  </code></pre>
  
  <p>I am able to fetch all the "name" field from events category using the below code.</p>
  
  <pre><code>drawAllEvents: function (events)  {
      var $container = $('#someID ul');
      $.each(events, function(i, event) {
          $('&lt;a /&gt;', { text: event.name, href: '#' }).wrap('&lt;li /&gt;').parent().appendTo($container);
      });
  }
  </code></pre>
  
  <p>Now I am trying to fetch "primitiveName" field from the markets array using another function but for some reason it returns undefined. Here is my code</p>
  
  <pre><code>drawAllBetTypesFilter: function (events)  {
      $('#bettype-sport ul').empty();
      var betTypeFilter = $('#bettype-sport ul');
      $.each(events, function (i, event) {
          $.each(event.markets, function (market) {
              var betTypeName = market.primitiveName;
              $('&lt;a /&gt;', {
                  text: betTypeName
              }).wrap('&lt;li /&gt;').parent().appendTo(betTypeFilter);
          });
      });
  }
  </code></pre>
  
  <p>Furthermore, How do I fetch third level array, for e.g If I want to fetch all "name" fields under "betTypes" which is a child of "markets" object.</p>
  
  <p>EDIT: 1 - Also mentioned in my comment. How do I group similar <code>primitiveName</code> values together in my list instead of displaying them seperately.</p>
  
  <p>Here is the fiddle to show how am I fetching values in first level. <a href="http://jsfiddle.net/7EYUB/2/" rel="nofollow">FIDDLE LINK</a></p>