```
     findCartItem:function(req,res){

    const myArray = [];

console.log('=====step:1=====');

db.Carts.findAll({
    where: {
        UserId: req.params.user
    }
}).then(data => {
    console.log('=====step:3=====');
for(let i =0;i<data.length;i++){
    db.Products.findOne({
        where: {
            id: data[0].dataValues.ProductInfo
        }
    }).then(cartData => {

        console.log('=====step:5=====');
        console.log(cartData.dataValues);
        const createdOn = getDbDate(cartData.dataValues.createdAt);
        let theProduct = {
            id: cartData.dataValues.id,
            userId: cartData.dataValues.userId,
            productName: cartData.dataValues.productName,
            serialNumber: cartData.dataValues.serialNumber,
            category: cartData.dataValues.category,
            price: cartData.dataValues.price,
            productDescription: cartData.dataValues.productDescription,
            condition: cartData.dataValues.condition,
            warranty: cartData.dataValues.warranty,
            packaging: cartData.dataValues.packaging,
            userUploadImage1: cartData.dataValues.userUploadImage1,
            userUploadImage2: cartData.dataValues.userUploadImage2,
            status: cartData.dataValues.status,
            verified: cartData.dataValues.verified,
            createdAt: createdOn
        };
        console.log('=====step:6=====');
        myArray.push(theProduct);
        /*now array is being populated*/
        console.log(myArray)
    });
}
    console.log('=====step:4=====');/*even at this point, array hasn't been populated*/
 res.send(myArray)
}).catch(err => console.log(err));

console.log('=====step:2=====');/*at this point array hasn't been populated yet*/
console.log(myArray);

    }

```

I cannot figure out why outside of the promise the array dumps its content. Any help with be greatly appreciated.
The code first defines the array at the top 
then it checks all the products the the user has in his cart with his user id 
then it takes all the products that he has (for this i took out the loop until i figure out why its not working) in the cart db. then it takes all that data and finds all the products details that each product has. then it adds the correct date format and pushes it to the array but out side of the promise it is gone.