Replace keys in template string with object properties

You can use replace with a callback :

var optionString = templateString.replace(/{(\w+)}/g, function(_,k){
      return obj[k];
});

Demonstration

Leave a Comment