title: Fast Javascript String Replacement
body: <p>Hey there geniuses of SO!</p>
  
  <p>This is for an autocomplete plugin that needs to accept data as an array of arrays and convert it using a format string (or regex). The format string could be any format.</p>
  
  <pre><code>var dataArray = [ ["data1-1", "data1-2", "data1-3"], ["data2-1", "data2-2", "data2-3"],... ];
  var format = "&lt;li&gt;{0} &lt;br /&gt; -- &lt;small&gt; {1}, {2}&lt;/small&gt;&lt;/li&gt;";
  // alternate formats could be: 
  //  "&lt;li&gt;{0}&lt;/li&gt;"
  //  "&lt;a href="{0}" title="{2}"&gt;{1} ({2})&lt;/a&gt;"
  // etc...
  
  function fillAutocomplete(datum,format){
      // do some magic here...
      // return "&lt;li&gt;data1-1 &lt;br /&gt; -- &lt;small&gt; data1-2, data1-3&lt;/small&gt;&lt;/li&gt;";
  }
  </code></pre>
  
  <p>The following idea works..but i'd like to see if anything would be faster...</p>
  
  <pre><code>var datum = data[0],
      html="&lt;li&gt;\{0\} &lt;br /&gt; -- &lt;small&gt; \{1\}, \{2\}&lt;/small&gt;&lt;/li&gt;";
  for(var i=0,l=datum.length;i&lt;l;++i){
      var reg = new RegExp("\\{"+i+"\\}");
      html=html.replace(reg,datum[i]);
  }
  </code></pre>
  
  <p>I'm open to new ideas on how to approach this problem.</p>