Skip to content Skip to sidebar Skip to footer

Cannot Split With " \ " In Js

i am trying to split my data using .split('\'), but its not working an error occurs 'Uncaught SyntaxError: Invalid or unexpected token'. can we split with '\'?

Solution 1:

You should just split on a String here because you need to escape the \ (String -> double quotes).

So .split("\\") it is.


Solution 2:

You can try with escaping this slash as follow

var str = "your\requirement";    
str.split("\\");

Solution 3:

The backslash is one character that needs to be escaped when using a string literal.

Try calling .split('\\') on your string.


Solution 4:

Use below syntax for escape the slash :

var str = "your string";
str  = str.split("\\");

Post a Comment for "Cannot Split With " \ " In Js"