access var into then from outside (scopes)

Hello,
I have a load function that fills a variable “dataGrid” in this way:

$$(“flightsGrid”).load(“https://testflight.free.beeceptor.com/my/api/get/flights”, params).then(
function(data){
let gridData = data;
$$(“flightsGrid”).sort(“sta_std”, “asc”, “date”);
});

How can I get the gridData value from outside the function?

console.log(gridData) returns undefined.
And I’m calling console.log after the data has been loaded.

I;ve tryed with this.gridData but i get the same…