Accessing an array outside an ajax call?

Accessing an array outside an ajax call?

all! I have an ajax call grabbing the results of an API. When I try to access that array outside the call, it's blank. Help?

all! I have an ajax call grabbing the results of an API. When I try to access that array outside the call, it's blank. Help?

In the code below, I get the list of properties, then assign the results to the "mlsArray" variable. When I console log it inside main, I get the desired result.

However, if I later call getHomes, the array is empty.

main(auth) {
$.ajax({async: false,
    url: "https://api.simplyrets.com/properties? 
limit=500&lastId=0&status=active&maxprice=" +
    this.maximum + "&type=residential",
    type: 'GET',
    dataType: 'json',
    // authorize with the API credentials
    beforeSend: function(xhr) {
        xhr.setRequestHeader("Authorization", "Basic  " + auth);
    },
    success: function(res) {
     this.mlsArray  = Object.assign([], res);
     console.log(this.mlsArray);
    }
  });
}

getHomes() { console.log(this.mlsArray); } }


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

An Angular Roadmap — The Past, Present, and Future of Angular

✅Interested in being an Angular developer in 2019? ... blog post it's most likely that you've written some code in javaScript in the past.