Typescript: How to push elements to Global Variable array and access outside of function [duplicate]

I’m a typescript/javascript beginner, and I’m having trouble understanding how Global Variables work. I’m trying to push elements into a Global Variable inside a function, and then access those contents outside of the function. However, when I try logging the array outside of the function, it returns an empty array. How can I access those contents outside of the function?

I want to do something like this:

        let myArray: string[] = [];

        getReports().then(reports => {
            reports.forEach((report) => {
                myArray.push(report.coolTitle);
            });
            //If I log myArray here, I can see a list of report titles
            cy.log(JSON.stringify(myArray));
        });

//I want to access the new contents of myArray out here, but it returns an empty list
cy.log(JSON.stringify(myArray));