Closure which return array

ahah, question about variable scope in closure ^^

Well, I found a lot of questions about this subject, but can't find any answer to my problem.

Here is the code :

var groups = [];
var users = [];

var getPermissions = function(accessList){
    var desk = [];
    _.forEach(accessList, function(access){
        desk.push(access.name);
        console.log("1 - Permission :" + desk);
    });

    return desk;
};

_.forEach(groups, function(group){
    _.forEach(users, function(user){
        var permissions = [];
        permissions = getPermissions(user.access);
        console.log("2 - Permission :" + permissions);
    });
});

Can you tell me why the log 1 give me answer, while the 2 is all the time empty :(

Thank you all

P.S : ignore the aim of the code, I deleted some parts of it ...

You need to make use of callback inorder to get the second console working, as by the time your function is getting executed it will display the console with blank array.

var getPermissions = function(accessList,callback){
    var desk = [];
    _forEach(accessList, function(access){
        desk.push(access.name);
        console.log("1 - Permission :" + desk);
    });

    callback(desk);
};

_.forEach(groups, function(group){
    _.forEach(users, function(user){
        var permissions = [];
       getPermissions(user.access,function(data){
    console.log("2 - Permission :" + data);   

     permissions =data;     
    });
});

});