title: Return value after all promises are resolved within a loop
body: <p>Given this IDs array:</p>
  
  <pre><code>var array = [1,2,3,4,5];
  </code></pre>
  
  <p>How can I return a promise AFTER all the other calls made within the loop are finished?</p>
  
  <pre><code>            var deferred = $q.defer(),
                  result = [];
  
              for (var i = 0; i &lt; array.length; i++) {
                  var id = array[i];
  
                  Tools.remove(campaignID).then(function(result) {
                      result.push(result.id);
                  }).catch(function (response) {
                      result.push(response)
                  });
              }
  
              deferred.resolve(result);
  
              return deferred.promise;
  </code></pre>