title: javascript replace globally with array
body: <p>You can use array for replacement:</p>
  
  <pre><code>var array = {"from1":"to1", "from2":"to2"}
  
  for (var val in array)
      text = text.replace(array, array[val]);
  </code></pre>
  
  <p>But what if you need to replace globally, ie
  text = text.replace(/from/g, "to");</p>
  
  <p>Array is pretty big, so script will take a lot of space if I write "text = text.replace(...)" for every variable.</p>
  
  <p>How can you use array in that case? 
  "/from1/g":"to1" does not working.</p>