javascript - What will this function return? An empty Array or Array of Objects -


var rowdata = [];  function somename() {     jsonclient.onload = function () {         rowdata.push("sasas");         rowdata.push("sasas1");         rowdata.push("sasas2");         rowdata.push("sasas3");     };      return rowdata; } 

this returns me empty rowdata. why?

guys typo mistake me while posting

the function somename never called (e.g. somename();). since never called, push statements never executed.

even if called, somename function assigns anonymous callback function jsonclient.onload. code doesn't show jsonclient is, seems safe assumption event handler http response. function won't called until http response received browser, time return statement have been executed. you can't return ajax request, have deal data in callback itself.


Comments