I am getting some weird behaviour with the following, it shows an array length of 0 eventhough printing it right before that shows that there clearly is a length greater than 0:
var getTopSelection = function(callback) {
var topSelection = [];
for(var i=0; i < markers.length; i++) {
if(markers[i].map !== null) {
var stationID = markers[i].id;
getTrips(stationID, globalFromDate, globalToDate, function(response) {
topSelection.push({
StationID: stationID,
Trips: response
});
}, function(error) {
console.log(error);
})
}
}
callback(topSelection);
};
getTopSelection(function(response) {
console.log(response); //115
console.log(response.length); //116
})
And this is shown in the inspector, the "length: 42" belongs to line 115.
Question: Why does it show a length of 0 eventhough it clearly says it has a length of 42 one line before?