I am retrieving building geolocation data from a service, however in some cases some of the data will have missing properties.

**Good data**

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

```

**Bad data**

Missing Region or Building Name

```
{
    "ModifiedOn": "2015-04-29 11:17:28.0",
    "BuildingName": "Kings Landing",
    "Latitude": "23.818051",
    "Longitude": "-.154871",
}

```

After making my AJAX request I store the JSON response in an object called *\_regionAndBuildings*

I want to clean out any bad data from it, so I tried the following code

```
console.log("Starting size of building data : " + _regionAndBuildings.length);
//clean json by setting object to undefined
for (var i = 0; i < _regionAndBuildings.length; i++) {
    if (_regionAndBuildings[i].BuildingName === undefined && _regionAndBuildings[i].Region === undefined) {
        console.log("Deleting");
        delete _regionAndBuildings[i];
    }
}
console.log("Ending size of building data after cleaning : " + _regionAndBuildings.length);

```

**Output**

> 
> Starting size : 209
> 
> 
> Delete x 17
> 
> 
> Ending size : 209
> 
> 
> 

Why is this code not removing the bad elements in my JSON object?