title: Javascript, global variable assignment from nested Promises
body: <p>I have method that resolves a promise that retrieves some Products</p>
  
  <pre><code>global.getProducts().then(function (prodPromised) {
  </code></pre>
  
  <p>For each prodPromised I have a Category ID but I also want the Category Name.
  So, I create an array of promises in which I assing the Category Name to each Product.</p>
  
  <pre><code>var products = [];
  
  for (var i = 0; i &lt; prodPromised.length; i++) {
      promises.push(self.createCatName(prodPromised[i]));
  }
  </code></pre>
  
  <p>After that I resolve the promises ...</p>
  
  <pre><code>Promise.all(promises).then((products) =&gt; {
  </code></pre>
  
  <p>... I loop them for some operations</p>
  
  <pre><code>for (var i = 0; i &lt; products.length; i++) {
  </code></pre>
  
  <p>The problem is that I'd like to store the array products in a "upper" position so to use it for another method.</p>
  
  <p>I suppose there's something related to the hoisting, but I dont' understand how to do it :-(</p>
  
  <p>Thanks</p>