javascript - jQuery.each() and Array Manipulation -


here's code:

$(document).ready(function() {     var myarray = [];     $.getjson("some url",function(data){         $.each(data, function(){             myarray.push("a string" + this);         });         alert(myarray);     });     //alert(myarray); }); 

the code shown working fine , displays array , contents.

however, when try display array having command line right after $.each code block (commented out in sample code), array , contents not displayed. empty/ blank message returned instead.

why happening , how can fix it? i'd have command "alert(myarray);" right after $.each block.

thank in advance!

var myarray = []; var jqxhr = $.getjson( "some url", function(data) {   $.each(data, function(){      myarray.push("a string" + this);   }); })  ;  jqxhr.complete(function() {   console.log(myarray); }); 

jquery xhr object, or "jqxhr," returned $.getjson()

when request complete, .complete() callback fired immediately.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -