I think that I'm looking for promise but I don't see how to use it in my case.
I would like to console.log('ended') only when all my async code is done.
I have a callback for the DZ.api but not for forEach(), what is the best way for doing that ?
_.forEach(filteredTracks, function(n) {
DZ.api('/playlist/'+ n.id +'/tracks', function(response) {
_.forEach(response.data, function(n) {
SP.api('/search/'+n.title, function(response) {
console.log(response);
});
});
});
});
console.log('ended');
Promise.all(arrayOfPromise).then(function (result) {})