As show in the code below, I'am trying to read a Json File and push some values from the json file into an array, if the array is accessed within the function, the value is correctly stored
But when the callback function ends, the array is empty Why does the array not contain the values pushed?
var latArray = new Array();
var longArray = new Array();
var getLatLong = d3.json("./SRC/ratp_2013.json", function (error, data){
for(i in data.stops)
{
longArray.push(data.stops[i].longitude);
latArray.push(data.stops[i].latitude);
}
console.log(longArray); //Prints the Array of latitudes
console.log(latArray); //Prints the Array of longitudes
});
console.log(longArray); //Prints an empty array.
console.log(latArray); //Prints an empty array.