0

I have a massive list of airports which I'm intending to use for autocomplete purposes.

I'm currently trying to get rid of some of it's contents which are of no use to me. This is how the contents of the file look like:

 { "Airports": [
     {
        "iata": "TSS",
        "iso": "US",
        "status": 1,
        "name": "East 34th Street Heliport",
        "continent": "NA",
        "type": "heliport",
        "size": null
    },
    {
        "iata": "FOB",
        "lon": "-123.79444",
        "iso": "US",
        "status": 1,
        "name": "Fort Bragg Airport",
        "continent": "NA",
        "type": "airport",
        "lat": "39.474445",
        "size": "small"
    },

I want to remove everything where type = heliport and finally save it back to my airports.json

I'm afraid I have no sample code to post since I have no clue what's the way to go here.

Although I have found this function which supposedly does what I'm trying to achieve.

function findAndRemove(array, property, value) {
   $.each(array, function(index, result) {
      if(result[property] == value) {
          //Remove from array
          array.splice(index, 1);
      }    
   });
}
findAndRemove(Airports, 'type', 'heliport');

Could this be used to process and then save it back to my airports.json file?

4ae1e1
  • 7,228
  • 8
  • 44
  • 77
user327685
  • 129
  • 9
  • Related: http://stackoverflow.com/questions/2722159/javascript-how-to-filter-object-array-based-on-attributes – k0pernikus Nov 01 '15 at 12:24

1 Answers1

0

Please change your code like this

function findAndRemove(array, property, value) {
    $.each(array, function(index, result) {
      if(( typeof result !== 'undefined'))
        if(result[property] == value) {
        //Remove from array
        array.splice(index, 1);
      }    
    });
}
findAndRemove(Airports["Airports"], 'type', 'heliport');
anas p a
  • 383
  • 5
  • 20