title: NodeJS: unable to create nested array
body: <p>In NodeJS, I want to create nested array, please check the below structure:</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Afghanistan",
      "helps": [
        {
          "questions": "questions 1"
        }
      ]
    },
    {
      "id": 2,
      "name": "Angola",
      "helps": [
        {
          "questions": "Question 5?"
        }
      ]
    },
  ]
  </code></pre>
  
  <p>Here, I'm using ExpressJs and MySQL. My intention is to create an array as above through MySQL. Please see the following code:</p>
  
  <p>See the model code:</p>
  
  <pre><code>commonSelectByCondition: function(params, errorcallback, successcallback) {
          var join = "";
          var order_by = "";
          if(typeof params.join != 'undefined' &amp;&amp; params.join != ""){
              join = params.join;
          }
          if(typeof params.order_by != 'undefined' &amp;&amp; params.order_by){
              order_by = params.order_by;
          }
          var query = "SELECT "+ params.select + " FROM " + params.table + join + "  WHERE " + params.condition + " " +order_by;
          // console.log(query);
          pool.query(query, function(error, results, fields) {
              if (error) {
                  console.log(error);
                  errorcallback(error);
              } else {
                  successcallback(results);
              }
          });
  },
  </code></pre>
  
  <p>Please see the controller code:</p>
  
  <pre><code>router.post('/country-help', function (req, res, next) {
      var select = "`id`,`name`";
      var table = "`countries`";
      var limit = limit;
      var offset = offset;
      var condition = " status = 'Active'";
      var params = {
          select: select,
          table: table,
          limit: limit,
          offset: offset,
          condition: condition
      }
      CommonModule.commonSelectByCondition(params, function(err,data){
  
      }, function (data) {
          if (data.length &gt; 0) {
              var response = {
                  resCode: STATUSCODE.OK,
                  response: data
              }
  
              const copy = [];
              let helps = [];
              data.forEach(function(item){
  
                  var jsonObj = {
                    "id":item.id,
                    "name":item.name,
                    "Helps":[]
                  }; 
  
                  //copy.push(jsonObj);
                  //copy.push({"helps": helps});
                  var select = "`question`,`gender`, `user_id`, `country`";
                  var table = "`my_help`";
                  var limit = limit;
                  var offset = offset;
                  var condition = "country = '"+item.name+"' AND is_active = '1'";
                  var params_inner = {
                      select: select,
                      table: table,
                      limit: limit,
                      offset: offset,
                      condition: condition
                  }
                  CommonModule.commonSelectByCondition(params_inner, function(err,data){
  
                  }, function (data) {
                      //console.log(data)
  
                      if(data.length &gt; 0) {
                         for (var i = 0; i &lt;= 1; i++) {
                              // console.log(data[0].gender);
                              var helps = {};
                              helps.question = data[0].question;
                              jsonObj.Helps.push(helps);
                          }
                      }
                  });
                  copy.push(jsonObj);
              });
              res.status(200).send(copy);
          }
      });
  });
  </code></pre>
  
  <p>The result is below and I see the <code>Helps</code> contains nothing.</p>
  
  <pre><code>[
    {
      "id": 1,
      "name": "Afghanistan",
      "Helps": [
  
      ]
    },
    {
      "id": 2,
      "name": "Albania",
      "Helps": [
  
      ]
    }
  ]
  </code></pre>