My code involves creating an array from 2 ajax requests.
var myId = 13;
var array = [];
var checkIFfollowing = function(id, username){
UserService.checkIfFollowing(id, myId)
.success(function (data) {
var post = {
is_following : data, //boolean
username : username
}
array.push(post);
}).
error(function(error) {
//error
});
}
UserService.GetUserById(user_id)
.success(function (data) {
angular.forEach(data, function(post){
checkIfFollowing(post.id, post.username)
})
}).
error(function(error) {
//error
});
The structure of the returned data is always consistent:
[{id:1, username:'ed'},{id:2, username:'joe'},{id:3, username:'bob'}]
However, after the loop, sometimes the indexes change and become inconsistent. Is there a way to ensure they remain consistent all the time?