Context of my problem :
I am trying to create an array of the google maps Longitude and Latitudes to use in a heatmap. I am able to get data from my localhost and want to be able to reference an array that I create within the subscribe function outside of the function.
When I console.log a all of my data it comes out perfectly. When I try to reference the this.heatmapData outside of the subscribe function it is empty.
Here is the code
this.result = this.examsApi.getExams()
.subscribe(data => {
this.examsList = data;
this.i=0;
var obj = JSON.parse(data);
var val;
this.heatmapData = [];
for (val in obj["index"]) {
console.log(this.heatmapData) // Fills perfectly
this.heatmapData.push(new google.maps.LatLng(obj["Latitude"][val], obj["Longitude"][val])); // The parameters are filled with longitude and latitude values a http.get request in another file.
}
});
console.log(this.heatmapData) // Becomes empty