I have this code. I need to see in the array y the objects assigned inside the for statement (increase and decrease). In the first console.log I can see the array updated but in the second it's empty.
function myfunction() {
var y = new Array(2);
    $.getJSON('../docs/natures.json', function(data) {
        var nature = document.getElementById("nature").value;
        for( var i = 0; i< data.natures.length; i++)
        {
            var x = data.natures[i];
            if((nature.localeCompare(x.name)) == 0)
            {
                y=[x.increase];
                console.log(y[0]);
                y.push(x.decrease);
                console.log(y[1]);
                break;
            }
        }   
        console.log(y);  <!- first ->
    });
console.log(y);  <!- second ->
}
my JSON file is like this :
{"natures":[
{
"name":"some name",
"increase": "some increase",
"decrease": "some decrease"
},
{...}
]}
 
     
    