title: Function to replace a substring with a function value in javascript
body: <p>I need a function which will accept test arguments and return a formatted response</p>
  <pre class="lang-js prettyprint-override"><code>format('Hello, {name}!', {name: 'world'}); // Hello, world!
  
  format('Hello, {user.name.first} {user.name.last}!', {user: {name: {first: 'John', last: 'Smith'}}}); // Hello, John Smith!
  
  format('Hello, {user.name.first.f1} {user.name.last}!', {user: {name: {first: {f1:'John'}, last: 'Smith'}}}); // Hello, John Smith!
  </code></pre>
  <p>I did this. But is it a good approach ? Basic idea was to convert the string to template. Is there any better approach ?</p>
  <pre class="lang-js prettyprint-override"><code>var format = (str, obj) =&gt; {
  
    str = str.replaceAll('{', '${obj.');
    let newStr = eval('`' + str + '`');
      
    console.log(newStr);
  }
  </code></pre>