I have an a string like the following,
var x = "[{"k":"1"}]";
console.log(x[0].K);
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
Uncaught SyntaxError: Unexpected identifier
I know,it beasuse of the 'double quotes' inside and outside of the array.
It is not even allowing me to parse it.
So,I thought
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," ]'"));
But still I am getting the same unexpeted identifier error,an anyone please suggest me help.Thnaks.