Array doesnt Update in JavaScript -


i have code. need see in array y objects assigned inside statement (increase , decrease). in first console.log can see array updated in 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 = 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 :

{"natures":[ { "name":"some name", "increase": "some increase", "decrease": "some decrease" }, {...} ]} 

my results in console

jquery.getjson asynchronous, callback function passed run when request complete.

console.log(y);  <!- second ->  

occurs prior that


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -