Javascript: How to iterate on array using promises?
问题 LIVE DEMO Given the following function: function isGood(number) { var defer = $q.defer(); $timeout(function() { if (<some condition on number>) { defer.resolve(); } else { defer.reject(); } }, 100); return defer.promise; } and an array of numbers (e.g. [3, 9, 17, 26, 89] ), I would like to find the first "good" number. I would like to be able to do this: var arr = [3, 9, 17, 26, 89]; findGoodNumber(arr).then(function(goodNumber) { console.log('Good number found: ' + goodNumber); }, function()