title: forEach not a function javascript
body: <p>I am trying loop through a JSON object to extract data from it. When I run my code I get the error:</p>
  
  <p>Type Error: element.listing.forEach is not a function.</p>
  
  <p>I would also like to note that I have done this earlier in my code and it works perfectly. I have tried the solutions posted on <a href="https://stackoverflow.com/questions/35969974/foreach-is-not-a-function-error-with-javascript-array">forEach is not a function error with JavaScript array</a>. None of them worked. THe string was just filled with white spaces. Here is my code:</p>
  
  <pre><code>var JSONBody = JSON.parse(body);
  var dataString = "";
  var count = 0;
  
  //Get required data from response body:
  JSONBody.forEach(function(element) {
  if(element.listing != null){
      element.listing.forEach(function (element2) {
          dataString = dataString + element2.media[0].url;
          dataString = dataString + "!!!";
          dataString = dataString + element2.propertyDetails.bedrooms;
          dataString = dataString + "!!!";
          dataString = dataString + element2.propertyDetails.bathrooms;
          dataString = dataString + "!!!";
          dataString = dataString + element2.propertyDetails.carspaces;
          dataString = dataString + "!!!";
          dataString = dataString + element2.propertyDetails.displayableAddress;
          dataString = dataString + "|||";
  
          //console.log(element2.media[0].url);
          count++;
      }, this);
      console.log(dataString);
      }else{
          dataString = "";
          console.log("Listings is NULL!");
      }
  }, this);
  </code></pre>
  
  <p>JSONBody looks like:</p>
  
  <pre><code>[ { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11658083,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'Ultra Modern Furnished Apartment with Stunning Views',
         summaryDescription: '&lt;b&gt;Ultra Modern Furnished Apartment with Stunning Views&lt;/b&gt;&lt;br /&gt;Brisbane\'s newest luxury complex \'Spire\' hits the market with huge popularity. Apartment 2704 offers the lucky resident the very best of the already stunning facilities and views with 27t...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [Array],
         inspectionSchedule: [Object],
         listingSlug: '2704-550-queen-street-brisbane-city-qld-4000-11658083' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 8980993,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'High Floor with views in Parkland Paradise &amp; Pet friendly\n',
         summaryDescription: '&lt;b&gt;High Floor with views in Parkland Paradise &amp; Pet friendly\n&lt;/b&gt;&lt;br /&gt;Lap up luxury living with the world’s largest inner-city sub-tropical parklands at your doorstep!! \r\n\r\n\r\n*\t3 good size bedrooms\r\n*\t2 bath rooms\r\n*\t1 car space\r\n*\t3 phone lines\r\n*\tFu...',
         hasFloorplan: true,
         hasVideo: false,
         labels: [],
         inspectionSchedule: [Object],
         listingSlug: '7054-7-parkland-blvd-brisbane-city-qld-4000-8980993' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11626727,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'STUNNING INNER CITY PARKLAND APARTMENT!',
         summaryDescription: '&lt;b&gt;STUNNING INNER CITY PARKLAND APARTMENT!&lt;/b&gt;&lt;br /&gt;A gorgeous inner city apartment capturing stunning parkland views, this two bedroom executive apartment offers it\'s new tenant a fantastic inner city lifestyle!\r\nComfortable, local and convenient, per...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [],
         inspectionSchedule: [Object],
         listingSlug: '3113-3-parkland-boulevard-brisbane-city-qld-4000-11626727' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11660275,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'ENJOY EXPANSIVE, UNINTERRUPTED VIEWS OVER THE BOTANIC GARDENS AND BRISBANE RIVER at ABIAN..!!',
         summaryDescription: 'ENJOY EXPANSIVE, UNINTERRUPTED VIEWS OVER THE BOTANIC GARDENS AND BRISBANE RIVER at ABIAN..!!&lt;br /&gt;Presenting an exclusive opportunity to lease this rare three bedroom luxury apartment. For executive renters wanting to secure a large, sophistica...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [Array],
         inspectionSchedule: [Object],
         listingSlug: '2702---140-alice-street-brisbane-city-qld-4000-11660275' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11660130,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'ABIAN - unprecedented luxurious lifestyle!!! LOCATION LOCATION LOCATION..',
         summaryDescription: '&lt;b&gt;ABIAN - unprecedented luxurious lifestyle!!! LOCATION LOCATION LOCATION..&lt;/b&gt;&lt;br /&gt;A SCULPTURAL RIVERFRONT MASTERPIECE BY SUNLAND GROUP - this building has to be seen to be believed.\r\n\r\nThis HUGE 160SQM 3 bedroom apartment on the 23rd floor offers o...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [Array],
         inspectionSchedule: [Object],
         listingSlug: '2302---140-alice-street-brisbane-city-qld-4000-11660130' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11660012,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'ABIAN BOTANIC GARDENS -BRISBANE\'S NEWEST BUILDING OFFERING WORLD-CLASS FACILITIES..!',
         summaryDescription: 'ABIAN BOTANIC GARDENS -BRISBANE\'S NEWEST BUILDING OFFERING WORLD-CLASS FACILITIES..!&lt;br /&gt;Located in the most sought after residential quarter of the CBD, you will have immediate access to the Botanical Gardens, South Bank as well as the abundan...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [Array],
         inspectionSchedule: [Object],
         listingSlug: '1601---140-alice-street-brisbane-city-qld-4000-11660012' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11658812,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'STUNNING 2 BED AT ABIAN BOTANIC GARDENS, $675 P/W..!',
         summaryDescription: '&lt;b&gt;STUNNING 2 BED AT ABIAN BOTANIC GARDENS, $675 P/W..!&lt;/b&gt;&lt;br /&gt;This large two-bedroom apartment embraces sweeping views over the Botanical Gardens, Brisbane River, Kangaroo Point cliffs and South Bank.\r\n\r\nThe bedrooms are generous in proportion and e...',
         hasFloorplan: true,
         hasVideo: false,
         labels: [Array],
         inspectionSchedule: [Object],
         listingSlug: '1301---140-alice-street-brisbane-city-qld-4000-11658812' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11629051,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'ABIAN  Brisbanes new standard in luxury living!!',
         summaryDescription: '&lt;b&gt;ABIAN  Brisbanes new standard in luxury living!!&lt;/b&gt;&lt;br /&gt;Enjoy uninterrupted views of the River City skyline, Botanical Gardens, Kangaroo Point Cliffs and South Brisbane. Positioned at the unrivalled location directly opposite the Botanic Gardens a...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [],
         inspectionSchedule: [Object],
         listingSlug: '3103-140-alice-street-brisbane-city-qld-4000-11629051' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11578249,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'SWEEPING RIVER VIEWS- EXQUISITE APARTMENT LIVING! 3 BEDROOM APARTMENT - MERITON!',
         summaryDescription: '&lt;b&gt;SWEEPING RIVER VIEWS- EXQUISITE APARTMENT LIVING! 3 BEDROOM APARTMENT - MERITON!&lt;/b&gt;&lt;br /&gt;Call Daleen on 0427 689 598 to arrange your inspection today!\r\n\r\nCentral CBD Location | River + City Views | Close to transport | Onsite Building Manager | Gym...',
         hasFloorplan: true,
         hasVideo: false,
         labels: [],
         inspectionSchedule: [Object],
         listingSlug: '501-adelaide-street-brisbane-city-qld-4000-11578249' } },
    { type: 'PropertyListing',
      listing:
       { listingType: 'Rent',
         id: 11657497,
         advertiser: [Object],
         priceDetails: [Object],
         media: [Array],
         propertyDetails: [Object],
         headline: 'AMAZING NEW WATER-VIEW APARTMENT AT ABIAN BOTANIC GARDEN IS NOW READY FOR RENT',
         summaryDescription: '&lt;b&gt;AMAZING NEW WATER-VIEW APARTMENT AT ABIAN BOTANIC GARDEN IS NOW READY FOR RENT&lt;/b&gt;&lt;br /&gt;This spectacular brand-new home on 16th floor features 2 bedrooms, 2 bathrooms, master bedroom with walk in robe and ensuite, air conditioning, single lockup gar...',
         hasFloorplan: false,
         hasVideo: false,
         labels: [],
         inspectionSchedule: [Object],
         listingSlug: '--140-alice-street-brisbane-city-qld-4000-11657497' } } ]
  </code></pre>