0
let testowy = v.za0+v._7a+v._1+v._1+v._13+v._3+v.za0+v._7a+v._1+v._1+v._13+v._12+v.za0+v._7a+v._1+v._1+v._13+v._11+v.za0+v._7a+v._1+v._1+v._14+v._5+v.za0+v._7a+v._1+v._1+v._14+v._10+v.za0+v._7a+v._1+v._1+v._5+v._15+v.za0+v._7a+v._1+v._1+v._5+v._16;

console.log(testowy) // output unicode "\u0061\u006c\u0065\u0072\u0074\u0028\u0029"
eval(testowy) // gives error
eval("\u0061\u006c\u0065\u0072\u0074\u0028\u0029") // OK - alert()

the question is how to make testowy variable to work as a string?

eval("'"+"testowy+"'") // or
eval("\""+"testowy+"\"") // doesn't work 

4
  • Which language? Could you give more details? Commented Mar 30, 2021 at 14:47
  • Does this answer your question? "Variable" variables in Javascript? Commented Mar 30, 2021 at 14:55
  • If not, what error are you getting? We don't know what v is. Commented Mar 30, 2021 at 15:01
  • 1
    if console.log is writing "\u0061\u006c\u0065\u0072\u0074\u0028\u0029" then the actual string was probably set using escaped slashes - \\u0061\\u006c\\u0065\\u0072\\u0074\\u0028\\u0029. You'll need to parse the string to unicode characters. Commented Mar 30, 2021 at 15:04

1 Answer 1

1

if console.log is writing "\u0061\u006c\u0065\u0072\u0074\u0028\u0029" then the actual string was probably set using escaped slashes -

\\u0061\\u006c\\u0065\\u0072\\u0074\\u0028\\u0029.

You'll need to convert the string of hexadecimal character codes to Unicode characters...

let testowy = v.za0+v._7a+v._1+v._1+v._13+v._3+v.za0+v._7a+v._1+v._1+v._13+v._12+v.za0+v._7a+v._1+v._1+v._13+v._11+v.za0+v._7a+v._1+v._1+v._14+v._5+v.za0+v._7a+v._1+v._1+v._14+v._10+v.za0+v._7a+v._1+v._1+v._5+v._15+v.za0+v._7a+v._1+v._1+v._5+v._16;

console.log(testowy); // outputs \\u0061\\u006c\\u0065\\u0072\\u0074\\u0028\\u0029

testowy = testowy.split('\\u')
    .map(s => {
        // ignore leading empty string.
        if (s !== '')
            return String.fromCharCode(parseInt(s, 16));
    })
    .join('');

console.log(testowy); // outputs alert()

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.