How do I Programmatically create a double escape?

No, you can’t. It’s not that the backslash is ignored in the split.

Instead, the problem is that the backslash isn’t in the string:

"Hello\ World"; // "Hello World"

Therefore, once the string literal has been parsed, you can’t recover the slash.

However, ECMAScript 6 introduces template strings. And with String.raw, you can recover the raw string form:

`Hello\ World`;           //  "Hello World"
String.raw`Hello\ World`; //  "Hello\ World"

Leave a Comment