title: Replace double backslash with single backslash in JavaScript
body: <p>I am writing a function that will remove a <code>\\</code> and replace it with a <code>\</code>. I notice that the code also does not work for backslashes that aren't powers of two (other than two, of course).</p>
  
  <pre><code>function x(input){
    var arr = [];
    for(var i = 0; i &lt; input.length; i++){
      var result = input[i].replace(/\\\\/g, '\\');
      arr.push(result);
    }
  
    return arr;
  }
  
  console.log(x(['\\a']));
  </code></pre>
  
  <p>The code will return <code>[ '\\a' ]</code>.</p>
  
  <p>EDIT:</p>
  
  <p>Here is a more complicated example:</p>
  
  <p>Input : <code>["\\\\\\"\\"a\\""]</code>
  Output : <code>[ '\\""a"' ]</code>
  Desired output: <code>["\\\"\"a\""]</code></p>