How can I replace this char \\
by \
by using javascript or jQuery? I tried this:
var string = "ABC\\testUserName"
var newString = string.replace("\\", "\")
I get this error:
Uncaught SyntaxError: Unexpected token ILLEGAL
How can I replace this char \\
by \
by using javascript or jQuery? I tried this:
var string = "ABC\\testUserName"
var newString = string.replace("\\", "\")
I get this error:
Uncaught SyntaxError: Unexpected token ILLEGAL
The \
is the escape character, so you need to double them in your replace()
call for them to be taken as a single instance. Try this:
var string = "ABC\\testUserName"
var newString = string.replace("\\\\", "\\");
console.log(newString);