im tring to push the return value of the resolve to a variable catWithItems which is outside the resolve. inside the resolve the catWithItems works as expected but when i console log catWithItems outside the loop it returns an empty array.
function categoriesSearch(req, res, next) {
    let categories = req.batch_categories;
    let catWithItems = [];
    _.forEach(categories, (category) => {
        return new Promise(resolve => {
            pos.categoriesSearch(req.tenant, category.id)
            .then(item => {
                if(item) category.items = item[0];
                return category;
            })
            .then(category => {
                catWithItems.push(category);
                console.log(catWithItems); //this is works inside here
                return resolve(catWithItems);
            });
        });
    });
    console.log(catWithItems); //doesn't work returns empty array
    res.json({categoryWithItems: catWithItems });
}this is the pos.categoriesSearch module. it makes a api call to square.(this works as expected)
function categoriesSearch(tenant, category) {
    let search_items_url = ${tenant.square.api.v2}/catalog/search,
        apiKey = tenant.square.api.key,
        payload = {
            "object_types": ["ITEM"],
            "query": {
                "prefix_query": {
                    "attribute_name": "category_id",
                    "attribute_prefix": category
                }
            },
            "search_max_page_limit": 1
        },
        conf = config(search_items_url, apiKey, payload);
        return request.postAsync(conf)
        .then(items => {
            return items.body.objects;
        });
} 
    