I'm running a loop to display characters of a specific Unicode escape sequence.
var es = '';
for (var i = 0; i <= 9999; i++) {
if (i < 10) {
es = '\\u000' + i;
} else if (i < 100) {
es = '\\u00' + i;
} else {
es = '\\u' + i;
}
console.log(es);
}
...however, it doesn't display the characters, just the sequence. Is there anyway in JavaScript to unescape the escaped sequence to force it show the character?
For anyone stumbling across this question (most likely my future self) looking to "unescape" a previously escaped Javascript special characters, here's a hacky way to do it:
newString = JSON.stringify(string).slice(1,-1)
However this seems to only work for certain characters, like \t, \n, \r, \f, \b, \\, etc.
To explain myself better, in the case of tabs, this will convert a tab character back into literal/raw string that is \t.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With