I have a weird Promise behavior which returns the incorrect value.
var years = []
$.getJSON('https://omdbapi.com?t=titanic&apikey=thewdb')
.then(function(movie){
years.push(movie.Year)
return $.getJSON('https://omdbapi.com?t=shrek&apikey=thewdb')
})
.then(function(movie){
years.push(movie.Year)
console.log(years) // ["1997", "2001"]
})
console.log(years) // [] return at the beginning
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
The empty array is being returned in the first place is from the end of the code - which is weird to me. Can you have to explain this? Thanks,