If you're just looking for standard escaping, you can use Template Literals ( https://developers.arcgis.com/arcade/guide/template-literals/ )
>>> my_string = `hello\nworld\t\tthis is \r\n\t a new line`
>>> Console(my_string)
hello
world this is
a new line
If you need to encode the strings with html characters like &, you'll have to implement the converter yourself I believe. I frequently have to replace `&` with `&` in our label expressions using `Replace('&', '&')`
You should also be able to use the ToCodePoint function if you need to encode unicode characters as escaped codepoints:
function encode(t){
var chars = []
var c
for (var char in t) {
c = t[char]
if (ToCodePoint(c) >= 255){
Push(chars, `\\u${ToCodePoint(c)}`)
} else{
Push(chars, c)
}
}
return Concatenate(chars, '')
}
Console(encode('hello world 🌏'))
----------CONSOLE----------
>> hello world \u55356\u57103