I am using node async feature. I am forming new array by iterating the existing array. I would like to return the new array after the call back is finished. res.json(arr) responds empty array. Help me identifying the problem.
getAllUsers(function(users) {
var arr = [];
async.forEach(users, function(user, callback) {
var id = user._id;
getAllCustomers(id, function(customers) {
var count = customers.length;
user.customers = count;
arr.push(user);
});
callback();
}, function(err) {
console.log('iterating done');
res.json(arr); // returns [], empty array
});
});