title: How to return value from nodejs callback function?
body: <pre><code>mturk_ops.block = function(callback){
  
  
  mongodb.collection(collectionName, function(err, collection){
  
      collection.distinct('workerId',function(err,result){
          var result1 = [];
          console.log(result.length);
          for(var i=0; i&lt; result.length;i++){
  
              console.log(result[i]);
  
            result1[result[i]] =  collection.count({
                  'workerId':result[i],
                  "judgementStat" : "majority"
              },function(err, count){
                  //  console.log(count);
                //  globals.push(count);
                  return count ;
                  // console.log( worker + ' majority : ' + count);
  
              });
  
          }
  
      console.log(result1);
      });
  
  
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Here I am trying to print 'result1' but its always printing array with undefined value. 'result1' is an array which is assigned out of the scope of callback function.</p>