I'm trying to read in a large local .json file to be manipulated in the code I'm testing. The below snippet loads it in, and returns it to my console.
var dataset;
$.getJSON("data.json", function(json) {
dataset = json.rows;
console.log(dataset);
});
However, when I put console.log() outside of the function, as below, I get "undefined" returned in the console, and receive errors elsewhere when trying to use the "dataset" variable.
var dataset;
$.getJSON("data.json", function(json) {
dataset = json.rows;
});
console.log(dataset);
New to JavaScript, but I thought you could alter an the external variable if it's declared outside of the function? Is there something with jquery or this particular function that I'm missing? The goal is to load the json's rows into a JavaScript object for manipulation, not limited to any scope.
Thanks!