I have an array of movies with IDs, but without ratings. I want to query a movie database to get the ratings for each movie, so I iterate over each object using fetch(url)
to query the API and then use .then(function(response) { add_rating_to_specific_movie})
.
The problem is, .then
is an async response, and I have no way of knowing which movie has returned a rating value so that I can mutate the correct movie object with the rating. And I can't create a new array with the returned values, because some movies will return status: movies not found
, and I have no way of knowing which movies are unrated.
Could use some guidance on a good algorithm for using promises here. Thanks!