The problem is that the FOR goes ahead while the ajax call retrieves the data from the URL, so only the last element into the array take the datum. How can I synch the for with the ajax call, in that case?
for(ii in scope.selMovies){
for(jj in scope.selMovies[ii]){
var title = scope.selMovies[ii][jj].title.replace(/\s*\(.*/, "");
var yearMovie = scope.selMovies[ii][jj].title.match(/\(.*(20|19)[\d]{2}/)[0].replace(/[^\d]/g, "");
http.jsonp(url + "&query=" + title + callb).
success(function (data) { console.log( ii, jj, title, data.results );
for (k in data.results){
if(data.results[k].release_date.substr(0, 4) == yearMovie ) {
scope.selMovies[ii][jj].infoes = data.results[k];
break;
}
}
}
);
}
}