I have a JavaScript script that makes a request to an api through the fetch api and then pushes the json response to a list and I want to access the response object inside the list through it's index but the item returns undefined like it isn't in the list.
I tried this:
let trendingMoviesDetails = []
fetch(`https://api.themoviedb.org/3/movie/529203?api_key=${key}&language=en-US&append_to_response=videos,release_dates`)
.then(response => response.json())
.then(response => {trendingMoviesDetails.push(response)})
console.log(trendingMoviesDetails, trendingMoviesDetails[0])
but why does the console print out trendingMoviesDetails[0]
as undefined
. This is the result on chrome:
[]0: {adult: false, backdrop_path: '/fmIp40ev4VGquK2bMo52PQgaV2d.jpg', belongs_to_collection: {…}, budget: 65000000, genres: Array(5), …}length: 1[[Prototype]]: Array(0)
undefined