I have a requirement where I want to replace all occurrences of ',' with '\,'. It works if I try to replace with other characters/strings, but seems to have some issue with '\,'.
'http://example.com/pqr?xyz=11,22.html'.replace(/,/g, '\,')
I expect to get result as 'http://example.com/pqr?xyz=11\,22.html'.
Thanks in advance !!
EDIT
After trying couple of answers (use '\\,' instead of '\,'), I found that console.log is escaping \ i.e it is showing single slash instead of double slash. When I use this variable, it is considering double slash value.
I am seeing two different results when I use console log vs not using console.log.