title: Push new field and value to json array object in node.js
body: <p>I'm new to node.js. I need to display Name in jqgrid, but I stored only id of one document into another document. </p>
  
  <p><strong>Example</strong></p>
  
  <p>I have 2 documents like Student master and student mark document. I have to display mark details in jqgrid. In mark document I stored student id instead of name. How do I fetch the name and send a new object to jqgrid?</p>
  
  <p>My code is as follows:</p>
  
  <pre><code>exports.getAllstudentsmark = function(req, callback)
  {
      studentsmarks.find(function(error, studentsmarks_collection) {
        if( error ) callback(error)
        else {
  
          studentsmarks_collection.toArray(function(error, results) {
            if( error ) callback(error)
            else {
              newresult = results;
              for(i=0;i&lt;results.length;i++)
              {
                  newresult[i]['studentname'] = getStudentName(results[i].studentid);
              }
              console.log(newresult);
              callback(null, newresult)}
          });
        }
      });
  }
  
  var getstudentObjectId = function(id)
  {
      return student.db.bson_serializer.ObjectID.createFromHexString(id);
  }
  var getStudentName = function(id)
  {
      student.findOne({_id: getstudentObjectId (id)}, function(e, o){
  console.log(o.name);
          return o.name;
      });
  }
  </code></pre>
  
  <p>newresult[i]['studentname'] is always getting undefined. But if I log into getStudentName function I can get answer into getStudentName function.</p>
  
  <p>My callback function is only getting this problem. How to resolve and get my result in an easy way. Please help any one.</p>