I am running `match()` to loop through an array or stop ID's. For each stop ID I am calling a function which loops through another array of route ID's and through the response of the AJAX call to find a match.

If it finds a match between the routeID and the RouteID in the array then it adds the result to another array in each loop.

My problem is that I can't find a way to determine when the functions called by the match() loop are complete.

The reason I need to do this, is that I need to make sure that the `jpFromStops` array is complete and ready to be processed by another function. 

What is the best way to do this?

```
   function match() {
        // Array length is 5
        for(i=0; i < fromStopsAr.length; i++) {
            getFromRoutesStopId(fromStopsAr[i]);
        }
        console.log("Match Array Output: " + jpFromStops.toString());
    }

function getFromRoutesStopId(id) {
   jpFromStops=[];
   tempAr = [];

  jQuery.ajax({
    type: "GET",
    url: 'http://apu-url.com/v1/gtfs/routes/stopid/'+id+'?api_key=API_KEY',
    dataType: "jsonp",
    cache: false,
    crossDomain: true,
    processData: true,

    success: function (data) {
    $.each( matchRoutes, function(index, value) {
      $.each(data.response, function(key, data) {
          if(data.route_short_name.toString() == value) {
             jpFromStops[jpFromStops.length] = id + ":" + value;      
          }
      });   
     }); 
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
      alert("There is a problem");
    }
  });
}

```

Console log Output:

```
Match Array Output: 
jp-main.js (line 177)
2
115
jp-main.js (line 199)
2
113
jp-main.js (line 199)
2
087

```