I have a function that reads integers from a JSON file and returns an array of those numbers. When I print the data, it's all there. However, when I check the length of the array before returning, I get a size of 0. Why?
function readJSON() {
    var arr = [];
    $.getJSON('foo.json', function(obj) {
        for(i = 0; i < obj.length; i++) {
            arr.push(obj[i]['_bar']);
            // Prints: 1 2 3 4 5
            console.log(obj[i]['_bar']);
        }
    });
    // Prints 0
    console.log(arr.length);
    return arr;
}
 
     
    