title: How to pass the argument to the promise function in the JavaScript for-each cycle
body: <p>I have the list of document elements. I want to change elements’ outerHtml with html. HTML is loaded from files in cycle, so I use promises. The problem is with passing the element to promise function in the cycle, because only the last element from array is passed.</p>
  
  <pre><code> ...
   /**
   * Set outer html of element.
   * @param element
   * @param newHtml
   */
  setOuterHtml = function(element, newHtml){    
      console.log("ELEMENT ", element); // always &lt;ge-test-2&gt;&lt;/ge-test-2&gt;
      element.outerHTML = newHtml;
  }
  
  this.loadElementsToHtml = function(){
      console.log(this.elements); 
      //[ge-survey, ge-test-1, ge-test-2]
      var promises  = [];
      for(var i=0; i&lt;this.elements.length; i++){
          var el = this.elements[i];
          // laod html from file
          var elPromise = this.loadHtml(el);
          // set outer html when HTML is loaded
          //// problem here with el !!! always ge-test-2 element
          elPromise.then(res =&gt; setOuterHtml(el,res)); 
          promises.push(elPromise);
      }
  
      return Promise.all(promises);
  }
  </code></pre>