title: Change string on each loop iteration
body: <p>I have the following problem: 
  I have a string and I need to replace for different regex parts.</p>
  
  <p>therefore I want to loop over it:</p>
  
  <p>In my case its a URL and I want to empty for specific parameters:</p>
  
  <pre><code>cleanURL(url, params) {
    params.forEach((param) =&gt; {
    url = this.updateUrlParameter(url, param, '');
  });
  </code></pre>
  
  <p>Whereas I have:</p>
  
  <pre><code>updateUrlParameter(url, param, value) {
    const regex = new RegExp(`(${param}=)[^&amp;]+`);
    const newURL = url.replace(regex, `$1${value}`);
    return newURL;
  }
  </code></pre>
  
  <p>This is the only way I got it to work, but now I am reassigning a function parameter.
  this is not what I want.</p>
  
  <p>My problem is, that</p>
  
  <pre><code>cleanURL(url, params) {
    params.forEach((param) =&gt; {
      this.updateUrlParameter(url, param, '');
    });
  }
  </code></pre>
  
  <p>Would always for each iteration pass the SAME <code>url</code> into the loop. And I end up with just the last replacement.</p>
  
  <p>I somehow would have to pass a changed string into the next loop iteration.</p>
  
  <p>How could I achieve this?
  Maybe into this direction?
  With somehow nesting and calling the function again?</p>
  
  <pre><code>while(outerI--){
    (function(i){
      i+=1;//doesn't affect outerI and you wanted 1-length so we add one.
  
      //crap inside your forEach loop but without the i++
    })(outerI)
  }
  </code></pre>
  
  <p>which I found here:
  <a href="https://stackoverflow.com/questions/11442129/foreach-loop-use-variable">.forEach loop: use variable</a></p>
  
  <p>Woudl be very glad for a hint here.
  thank you</p>
  
  <p>Cheers</p>