title: Replace multiple occurence string using array element
body: <p>I have several strings in an associative array:</p>
  
  <pre><code>    var arr = {
          '============================================': '---------',
          '++++++++++++++++++++++++++++++++++++++++++++': '---------',
          '--------------------------------------------': '---------'
      };
  </code></pre>
  
  <p>I want to replace occurrences of each key with the corresponding value. What I've come up with is:</p>
  
  <pre><code>    for (var i in arr)
      {
          strX = str.replace(i, arr[i]);
  
          console.log('arr[\''+i+'\'] is ' + arr[i] + ': ' + strX);
      }
  </code></pre>
  
  <p>This works, but only on first occurence. If I change the regex to <code>/i/g</code>, the code doesn't work.</p>
  
  <pre><code>for (var i in arr)
  {
      strX = str.replace(/i/g, arr[i]);
  
      console.log('arr[\''+i+'\'] is ' + arr[i] + ': ' + strX);
  }
  </code></pre>
  
  <p>Do you guys know how to work around this?</p>