I have a function which takes a url array and fetches the titles of those url's using npm package 'read-titles'. It successfully console.log the titles but does not push it into array.The array prints empty. The code is
function getTitleArray(addresses) {
    var titles = [];
    if (addresses.length > 1) {
        addresses.forEach((urls) => {
            console.log(urls.search('http'));
            if (urls.search('http://') == -1) {
                urls = 'http://' + urls;
            }
            readTitle(urls).then((title) => {
                titles.push(title);
                console.log(title);
            }, (err) => {
                res.status(400).send(err);
            });
        });
    }
    console.log('Titles are: ' + titles);
    return titles;
}
 
     
    