javascript - Value of the variable becomes empty when accessed outside the function in node js -


i have following code :

for(var index in workload.elements) { var arr = []; var resourceidentifiers = {}; var elementinfo = {}; var metadatamodified = {};

        elementinfo = workload.elements[index];           arr[index] = workload.elements[index].uri;         if(workload.elements[index].parameters.imageuri)         {             arr.push(workload.elements[index].parameters.imageuri);         }         resourceidentifiers = arr.join(',');         console.log('uri' + resourceidentifiers);          // connects mysql , fetch data         mysql.elementlevelpricing(resourceidentifiers, function(result){          elementlevelpricingsummary = json.stringify(result,null,2);         console.log('resultin' + elementlevelpricingsummary);          });          console.log('resultout' + json.stringify(elementlevelpricingsummary,null,2))      } 

the value of variable elementlevelpricingsummary becomes empty {} when accessed outside called function mysql.elementlevelpricing().

the function passed mysql.elementlevelpricing asynchronous callback, running after console.log line below it. you'll want need data in callback itself.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -