I have been trying to find a solution for this, and I've found similar things, but not exactly the same as this problem.
for (var i = 0; i < userArray.length; i++) {
var username = userArray[i];
var employee_id = $('#' + username + '_corresponding_employee_id').val();
followUserBatch(user, username).done(function(data) {
// How to get the correct value of username in here?
outcomes.done.push(username);
})
}
Basically what ends up happening is that when I do outcomes.done.push(username);
, username is always the last value of userArray
.