Task:
I have a function playlist.expand()
that returns a promise with data like [Item1, Item2, Item3]
. I have a collection of these playlists and want to concat the data returned from all expand()
functions and return it as a flat array. However I am stuck in the following code. I am hoping a few extra pair of eyes could help me spot the error:
Code:
breakdownPlaylist() {
return this.playlists.reduce( (acc, playlist) => {
acc.push( playlist.expand().then(result => result.collection));
return acc;
}, []);
}
$onInit() {
console.log('test', this.breakdownPlaylist());
}
Issue:
test is equal to []
at the time of execution. I can't understand why.