title: Promise.map within a Promise.map
body: <p>I'm trying to do a return of JSON object using a Bluebird's Promise.mapSeries/Promise.map within a Promise.mapSeries/Promise.map but I am unable to return them correctly. The function is as follows:</p>
  
  <pre><code>function getMovieDetails(link){
  return new Promise(function(resolve, reject) {
      request(link, function(error, response, body){
          var request = Promise.promisifyAll(require("request"), {multiArgs: true});
  
          var $ = cheerio.load(body);
  
          var movieYears = "Years";
          var movieYearLinks = [];
  
          movieYearLinks.each(function(index, item) {
              var movieYear = $(item).text();
              var movieYearLink = $(item).attr("href");
              movieYearLinks.push(movieYearLink);
          });
  
          Promise.mapSeries(movieYearLinks, function(url) {
              return request.getAsync(url).spread(function(response,body) {
                  var $ = cheerio.load(body);
                  var movie = {};
                  var year = "YEAR".text();
  
                  movie["year"] = year;
  
                  var movieActorsArray = [];
                  movieActors.each(function(index, item){
                      var movieActor = $(item).text();
                      movieActorsArray.push(movieActor);
                  });
                  movie["movieActors"] = movieActorsArray;
  
                  var recommendedMovies = //SOME ROWS;
                  var recommendedMoviesLinks = [];
  
                  recommendedMovies.each(function(jndex, jtem){
                      var recommendedRowObject = {};
  
                      var recommendedText = .text();
  
                      var recommendedLink = .attr("href");
  
                      recommendedRowObject["recommendedText"] = recommendedText
                      recommendedRowObject["recommendedLink"] = recommendedLink
                      recommendedMoviesLinks.push(recommendedLink);
                  });
  
                  Promise.mapSeries(recommendedMoviesLinks, function(url) {
                      return request.getAsync(url).spread(function(response,body) {
                          var $ = cheerio.load(body);
                          var obj = {};
                          //  GET SOME OTHER DESCRIPTION FROM THE RECOMMENDED MOVIE LINK
  
                          return obj;
                          });
                  }).then(function(results) {
                      // results here returns an array of recommended movie links objects.
                  }).catch(function(err) {
                  });
                  return main;
              });
          }).then(function(results) {
              // results here returns an array of movies
  
              //  I want to be able to link each movie with its recommended movies.
          }).catch(function(err) {
              console.log("Big Error " + err);
          });
      });
  });
  </code></pre>
  
  <p>}</p>
  
  <p>Some explanation of my code and context.</p>
  
  <p>The home page is a page with movie years. I've looped through them to get the links of the years and put into an array movieYearLinks.</p>
  
  <p>Next, I've used Promise.mapSeries to get some basic info on the movies. Within that basic info, there is are recommended movie link listed in a table. I've looped them through and put them into an array, recommendedMoviesLinks.</p>
  
  <p>After which, I'm going in to grab some other recommended movie (recommendedMovieObject) info before. </p>
  
  <p>I want to create a JSON object with all these info. The JSON object should be something like </p>
  
  <blockquote>
    <p>{ movieYear: 2017, movieLink: ..., recommendedMovies (This is an array
    of recommendedMovieObjects): }</p>
  </blockquote>
  
  <p>I'm open to any solution to achieve this. Thank you in advance.</p>