I have this code in Javascript:
var words = [];
d3.json("myFile.json", function(data) {
words = data.words;
console.log(words); //Log output to console
});
console.log(words); //Log output to console
The first console.log(words); shows an array of seven objects.
But the second console.log(words); shows an empty array. So it looks like words outside of the d3.json function is not the same as words inside that function.
I also have tried to use console.log(window.words); outside of the function and it still shows an empty array.
How can I get the data that I have read from myFile.json in the d3.json function, outside of that function?