title: Javascript string.replace not working with my arrays, what am I doing wrong?
body: <p>So I have three Arrays: </p>
  
  <ul>
  <li>str (containing the strings in which I want to replace something)</li>
  <li>replace (containing the letters to replace)</li>
  <li>by (containig the new letters)</li>
  </ul>
  
  <p>Here's my code, it goes through the function but returns the same as it gets. The goal is for it to replace "W" with "0", "B" with "1" and so on. What am I doing wrong?</p>
  
  <pre><code>function internalArtNrGenerator() {
  
      var str = new Array("5 1 1 1 0 W 1 1", "5 1 1 1 0 B 1 1", "5 1 1 1 0 K 1 1");
      var replace = new Array("W", "B", "K", "M", "A", "S", "N");
      var by = new Array("0", "1", "2", "3", "4", "5", "6");
  
      function str_replace(replace, by, str) {
          for (var i = 0; i &lt; replace.length; i++) {
              str = str.replace(new RegExp(replace[i], "g"), by[i]);
          }
          return str;
      }
  
  }
  </code></pre>