title: Cleaning out bad JSON data from object?
body: <p>I am retrieving building geolocation data from a service, however in some cases some of the data will have missing properties.</p>
  
  <p><strong>Good data</strong></p>
  
  <pre><code>[{
      "ModifiedOn": "2015-04-29 11:17:28.0",
      "BuildingName": "Wintefell",
      "Latitude": "52.900619",
      "Longitude": "-1.434602",
      "Region": "The North",
  }, {
      "ModifiedOn": "2015-04-29 11:17:28.0",
      "BuildingName": "Water Gardens",
      "Latitude": "51.818051",
      "Longitude": "-.354871",
      "Region": "Dorne"
  }]
  </code></pre>
  
  <p><strong>Bad data</strong></p>
  
  <p>Missing Region or Building Name</p>
  
  <pre><code>{
      "ModifiedOn": "2015-04-29 11:17:28.0",
      "BuildingName": "Kings Landing",
      "Latitude": "23.818051",
      "Longitude": "-.154871",
  }
  </code></pre>
  
  <p>After making my AJAX request I store the JSON response in an object called <em>_regionAndBuildings</em></p>
  
  <p>I want to clean out any bad data from it, so I tried the following code</p>
  
  <pre><code>console.log("Starting size of building data : " + _regionAndBuildings.length);
  //clean json by setting object to undefined
  for (var i = 0; i &lt; _regionAndBuildings.length; i++) {
      if (_regionAndBuildings[i].BuildingName === undefined &amp;&amp; _regionAndBuildings[i].Region === undefined) {
          console.log("Deleting");
          delete _regionAndBuildings[i];
      }
  }
  console.log("Ending size of building data after cleaning : " + _regionAndBuildings.length);
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <blockquote>
    <p>Starting size : 209</p>
    
    <p>Delete x 17</p>
    
    <p>Ending size : 209</p>
  </blockquote>
  
  <p>Why is this code not removing the bad elements in my JSON object?</p>