Passing data from one promise to another using then I'm trying to get an object with ratings and titles properties:
{
  ratings: [3, 5],
  titles: ['Movie1', 'Movie2']
}

from the following two functions:
const getMovies = () =&gt; {
  return new Promise((resolve) =&gt; {
    resolve([
      {
        movieId: 1,
        rating: 3
      },
      {
        movieId: 2,
        rating: 5
      }
    ]);
  });
};

const getTitle = (movieId) =&gt; {
  return new Promise((resolve, reject) =&gt; {
    switch (movieId) {
      case 1:
        resolve({ title: &quot;Movie1&quot; });
        break;
      case 2:
        resolve({ title: &quot;Movie2&quot; });
        break;
      default:
        reject(new Error(&quot;404 - movie not found&quot;));
    }
  });
};

I'm avoiding async/await, so trying to get that result using then.
Here is my approach:
const result = {}

getMovies()
  .then((movies) =&gt; {
    result.ratings = movies.map(({rating}) =&gt; rating)
    return Promise.all(movies.map(({ movieId }) =&gt; getTitle(movieId)));
  })
  .then((titles) =&gt; {
    result.titles = titles.map(({title}) =&gt; title)
    console.log(result)
  })
  .catch(console.log)

Can I do this in a better way withou having to nest then inside then? I don't like the use of a external variable to gather my result, but I don't like the nested thens in this other approach:
getMovies()
  .then((movies) =&gt; {
    Promise.all(movies.map(({ movieId }) =&gt; getTitle(movieId)))
      .then((titles) =&gt; {
        console.log({
          ratings: movies.map(({rating}) =&gt; rating),
          titles: titles.map(({title}) =&gt; title),
        })
      })
      .catch(console.log)
  })
  .catch(console.log)

How can I improve this using then and not async/await?
You could do like so if you prefer, essentially just pass forward the data i the promises. You could write your own promiseAllObject if you want it to be slightly neater.
const result = getMovies()
  .then(movies =&gt; {
    return Promise.all([
      Promise.all(movies.map(({ movieId }) =&gt; getTitle(movieId))),
      movies.map(_ =&gt; _.rating)
    ]);
  })
  .then(([titlesObj, ratings]) =&gt; ({
    titles: titlesObj.map(_ =&gt; _.title),
    ratings
  }))
  .catch(console.log);

result.then(r =&gt; console.log(r));