AnsweredAssumed Answered

Array undefined when populate Array at Callback function?

Question asked by aazizmajid on Nov 20, 2018
Latest reply on Nov 20, 2018 by aazizmajid

I am using ESRI JS API 3.24 in my application.


I am facing array undefined when populate Array at QueryTask.execute() Callback function. I have a large data to populate in callback function.


var myArray = []; //global variable
function main() {

    queryTask = new esri.tasks.QueryTask(LyrURL);
    query = new esri.tasks.Query();
    query.returnGeometry = false;
    query.outFields = ['*'];
    queryx.where = "NAME = '" + myVariableName + "'";
    queryTaskx.execute(queryx, populateData);
    console.log(myArray[1]); /*Error: undefined*/
    /*More code*/

function populateData(results) {
    //Here pushing/populating "myArray"     
    //The Data is large, lets say 2000 features   


After debugging it appears that the execute function is not calling populateData function until afterconsole.log(myArray[1]);

Can someone help me fining what I am doing wrong?