title: passing a variable to the replace_str mehtod in javascript
body: <p>I know that i can pass strings to the <code>replace_str</code> method in javascript. </p>
  
  <p>But what i really want is to be able to pass variables to make it dynamic. The problem is, every time i try to pass a variable to the method it doesn't work.</p>
  
  <p>I'm coming from php and it's pretty easy to do it with the <code>substr_replace();</code> method. Now what is the equivalent in javascript.</p>
  
  <p>Here is my code:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;p&gt;Click to test the result.&lt;/p&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function myFunction() {
    
      var full_string = "http://ok.ru/video/42597812745";
      var code = full_string.substr(19, 11);
  
      //Testing if this is working
      //document.getElementById("demo").innerHTML = code;
  
      r_frame = '&lt;iframe width="600" height="400" src="//ok.ru/videoembed/41680046601" frameborder="0"   allowfullscreen&gt;&lt;/iframe&gt;';
  
      var str_to_be_replaced = r_frame.substr(57, 11);
      //Testing if this is working
      //document.getElementById("demo").innerHTML = str_to_be_replaced;
    
    var res = str.replace(code, str_to_be_replaced);
    document.getElementById("demo").innerHTML = res;
    //Not working
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p&gt;Click to test the result.&lt;/p&gt;
  
  &lt;button onclick="myFunction()"&gt;Try it&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>