How can I set the var response in the socket.onmessage function. The var response is undefinded but I had set in the function. But I need the response variable because of the callback at the end of my function.
function getVariables_Groups(_callback) {
            var self = this;
            var response = {};
            socket.onmessage = function(evt) {
                json = JSON.parse(JSON.parse(evt.data));
                var statistics = {};
                var groups = json.args;
                statistics.action = "internal_dashboard_statistics";
                if(groups[0] == "notfound") {
                    statistics.args[0] = "notfound";
                    loadVariable("dashboard.htm", statistics);
                } else {
                    statistics.args = [];
                    for(var i = 0; i < json.args.length; i++) {
                        statistics.args[i] = {};
                        statistics.args[i].name = groups[i];
                    }
                    console.log(statistics);
                    self.response = statistics;
                }
            }
            console.log(response);
            _callback(response);
        }
 
    