title: Javascript regex to replace multiple words with new words
body: <p>I'm trying to replace multiple words with new words, each time I'm rendering an HTML template.</p>
  
  <p>Instead of having to loop through the template (which is quite big) three times to look for three different words, I'd like to <strong>combine the three words and their replacements</strong>, and only loop through the template once. (Also, obviously below code only replaces the last word, {id} since it overrides the other two replacement attempts above it).</p>
  
  <pre><code>       $.get('/templates/list-item.html', function(data) {
            var template = data,
                tmp = '';
  
            $.getJSON('conf.json', function(data) {
              var items = [],
                  list = data.default;
  
              for (var item in list) {
                var name = item.name,
                    value = list[item].value,
                    id = list[item].id;
  
                tmp = template.replace('{name}', name);
                tmp = template.replace('{value}', value);
                tmp = template.replace('{id}', id);
  
                items.push(tmp);
              }
  
              $('&lt;div/&gt;', {
                html: items.join('')
              }).appendTo('body');
            });
          });
  </code></pre>
  
  <p>Obviously rendering templates shouldn't be done with JS, but since it's for internal use only, no backend is available and it doesn't need to be indexed by Google, it's fine for the time being. </p>