First of all, i'm new in JS. I have a function that possibly can use multiple requests to get the final data. How can i do this in the right way? In this example participants won't pushed to the dialogs array because it's in async call.
function getDialogs(token, callback) {
    //getting user id
    con.query("SELECT user_id FROM users_tokens WHERE user_token = '" + token + "'", function(error, results) {
        if (error) {
            throw error;
        }
        var userId = results[0].user_id;
        //getting all conversation
        con.query("SELECT cc.id as conversation_id, cc.type FROM chat_conversations cc INNER JOIN chat_participants cp ON cc.id = cp.conversation_id WHERE cp.user_id = " + userId + " GROUP BY cc.id", function (error, results) {
            if (error) {
                throw error;
            }
            var dialogs = [];
            for (let i = 0; i < results.length; i++) {
                var dialog = {id: results[i].conversation_id};
                //getting chat participants
                con.query("SELECT user_id FROM chat_participants WHERE conversation_id = " + results[i].conversation_id + " AND user_id != " + userId, function (error, results) {
                    var participants = [];
                    for (let j = 0; j< results.length; j++) {
                        participants.push(results[j].user_id);
                    }
                    dialogs[participants] = participants;
                });
                dialogs.push(dialog);
            }
            callback(dialogs);
        });
    });
}
 
    