I have tried a few methods and been reading round but I cannot seem to figure out how to return the names array from this function.
function getNames(oauth2Client, docs) {
const api = x('v1');
let names = [];
return Promise.each(docs, function(doc) {
        let req = api.users.messages.get;
        let options = ({
            auth: oauth2Client,
            'userId': 'me',
            'id': doc.id
        });
        return Promise.promisify(req)(options).then(function(response) {
            for (y = 0; y < response.names.length; y++) {              
                names.push(response.names[y].toLowerCase());                
            }
        })
        .catch(function (err) {
            console.log('An error occured: ' + err.message);
            throw err;
        });
    });
}
 
     
    