Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

8
  • In let notificationList = JSON.parse(notificationParent.replace(/\\/g, '\\\\')), had I been passing an array containing a string, would I have been able to call .replace(). Cant I thus be sure that notificationParent and the result after replace are indeed a string? I tried let notificationList = JSON.parse(notificationParent.toString()) and got Unexpected token x in JSON at position 3. Commented Apr 26, 2017 at 8:07
  • I got to know that \x is not allowed from the answer at stackoverflow.com/questions/27059765/… Commented Apr 26, 2017 at 8:08
  • Some other answer somewhere suggested to replace \x with \u00. That didnt help too and anyway that solution isnt feasible for me since the some_url part above also contains \x and I dont want to disturb that. Commented Apr 26, 2017 at 8:10
  • 1
    JSON.parse should not even see the \x because it will be replaced before going into the function: console.log('\xe0') => à vs. console.log('\xe' + '0') => SyntaxError: Invalid hexadecimal escape sequence Commented Apr 26, 2017 at 8:27
  • 1
    If your string contains double slashes one can unescape it like this: '\\xe0\\xa4\\xa5\\xe0\\xa4\\xa1\\xe0\\xa4\\xa5\\xe0\\xa4\\xa1\\xe0\\xa4\\xa6\\xe0\\xa4\\xaf followed you'.replace(/\\x([0-9a-f]{2})/g, function(_, pair) { return String.fromCharCode(parseInt(pair, 16)); }) => "थडथडदय followed you" Commented Apr 26, 2017 at 8:32