title: How to replace backslash with two blackslashes in Javascript
body: <p>I have a string in following format.</p>
  
  <pre><code>var myStrg = "domain\john";
  </code></pre>
  
  <p>I need to replace <code>\</code> with two <code>\\</code> characters as <code>domain\\john</code>.</p>
  
  <p>How can I achieve this?</p>
  
  <p>I already went through many similar questions and answers but none of them had a answer for this.</p>
  
  <p>Any suggestions would be greatly appreciated.</p>
  
  <p>EDIT 01:</p>
  
  <p>To make this question clear, I'm adding more background information here with my code. As you can see the <code>username</code> is a parameter. Its format will be something like <code>'domain_name\user_name'</code>. So when I append this <code>username</code> to the URL the problem occurs. And I don't have control over the receiving value as the username.</p>
  
  <pre><code>function myFunction(username) {
  var fullurl = "http://myserver/mysite/_api/web/lists/getbytitle('MyTestList')/items?$select=ID&amp;$filter=Username eq '" + username + "'";
  
  NWF$.ajax({
      url: fullurl,
      method: "GET",
      async: false,
      headers: { "Accept": "application/json; odata=verbose" },
      success: function (data) {
          //process returned data here
      },
      error: function (data) {
          alert('Error occurred.');
      }
  });
  </code></pre>
  
  <p>}</p>