I have an asynchronous API call that returns me an array from the backend:
const call = PlayListsAPI.songsFromPlayList("default")
console.log(call)
As I suppose the returns at this moment is that I expect:
Promise { <state>: "pending" }
<state>: "fulfilled"
<value>: Array(3) [ {…}, {…}, {…} ]
The problem come when try to push the content of the array into other, once I get the resolved data from the promise, like this:
const dataFromPromise = []
const call = PlayListsAPI.songsFromPlayList("default")
.then(data => {
for (const song of data) {
dataFromPromise.push(song)
}
})
Doing this, the dataFromPromise
array is empty after the .then
call:
Array []
And the promise is still ‘pending’:
Promise { <state>: "pending" }
<state>: "fulfilled"
Where am I failing?
Thanks in advance, if another info is needed tell me 🙂