title: How to parse a string to array in js
body: <p>I have an a string like the following,</p>
  
  <pre><code>var x = "[{"k":"1"}]";
  console.log(x[0].K);
  </code></pre>
  
  <p>I ant hange this string sine I am getting from the server.Its out of my control.
  I want to display the 'k' value and when I onsole it,got </p>
  
  <pre><code>  Uncaught SyntaxError: Unexpected identifier
  </code></pre>
  
  <p>I know,it beasuse of the 'double quotes' inside and outside of the array.</p>
  
  <p>It is not even allowing me to parse it.</p>
  
  <p>So,I thought</p>
  
  <pre><code>1)Replace "[  and ]" as '[  and ]'  so it becomes
  
   '[{"k":"1"}]'
  
  2)Then I can parse and get the 'k' value.
  
  var x = "[{"k":"1"}]";
  console.log(x.replace(/"[/g," '[ ").replace(/"]"/g," ]'"));
  </code></pre>
  
  <p>But still I am getting the same unexpeted identifier error,an anyone please suggest me help.Thnaks.</p>