title: How to map array of json data in node js
body: <p>am using <code>map</code>function in my code i would like to pring Qdata of below array but here it says undefined may be it is inside the array of json if am wrong please help me to correct this!
    my array structure is like this</p>
  
  <pre><code>    [ { _id: 201,
          user_id: 141,
          PAN: 1,
          Qdata: 023444 } ]
  </code></pre>
  
  <p>here is the map fun:</p>
  
  <pre><code>    var data = array.map(function(p){
      return p.Qdata
      })
  </code></pre>
  
  <p>My actual code:</p>
  
  <pre><code>function getTotal(req, res, next) {
      var array = [];
      var array2 = {};
      db.users.find(req.q).toArray(function(err, rest) {
          rest.map(function(ids) {
              array.push(ids._id);
          })
          var total = array.length;
          for (var i = 0; i &lt; array.length; i++) {
              db.users.find(array[i]).toArray(function(err, users) {
                  if (err) return next(err);
              });
              db.consumer.aggregate([{
                  $unwind: "$votes"
              }, {
                  $match: {
                      'consumer_id': mongoskin.helper.toObjectID(array[i])
                  }
              }, {
                  $group: {
                      _id: "$votes.date",
                      "consumer_id": {
                          $first: "$consumer_id"
                      },
                      "vote": {
                          $sum: {
                              $cond: [{
                                  '$gt': ['$votes.score', 0]
                              }, "$votes.score", 0]
                          }
                      }
                  }
              }], function(err, sort_res) {
                  array2.push(sort_res);
                  total -= 1;
                  if (total &lt;= 0) {
  
                  var user_obj = {};
                  for (var i = rest.length - 1; i &gt;= 0; i--) {
                  var userDetails = rest[i];
                 user_obj[userDetails._id] = userDetails;
              }
  
               var aa=array2.map(function(p){
                  p.userDetails = obj[p.consumer_id];--------&gt; here am not getting consumer_id
                  return p
              })
                  res.send(aa)
                  }
  
              })
          }
  
  
      })
  }
  </code></pre>