title: I can't return a object in .then() Promise
body: <p>I created an object of ids, however I can not access it outside of my for or in my next .then (), i make det as global variable, does anyone know where it is wrong?</p>
  
  <pre><code>.then(function(idHome){
  
      home_id = idHome;
  
      var detname_img = [];
      var sqlEdit = "INSERT INTO images_det SET ?";
  
      for(var k = 0; k &lt; object.det_img.length; k++){
  
          detname_img.push({
              name_img : object.det_img[k].name_img,
          });
  
          connection.query(sqlEdit,detname_img[k]);
      }
  
      // console.log(detname_img);
  
      for(var i = 0; i &lt; detname_img.length; i++){
  
          var getDet = ("SELECT det_id from images_det where name_img = '" + detname_img[i].name_img + " ' order by 1 desc limit 1");
  
          connection.query(getDet, function(erro, result){
  
              for(var k = 0; k &lt; result.length; k++){
  
                  det.push({
                      det_id : result[k].det_id
                  });
                  console.log(chalk.blue(det[0].det_id));
                  return det;
              }
          });
      }        
  
  });
  </code></pre>