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 

General Grievance
  • 4,555
  • 31
  • 31
  • 45
sieja
  • 17
  • 4
  • Which language? Could you give more details? – Giacomo Catenazzi Mar 30 '21 at 14:47
  • Does this answer your question? ["Variable" variables in Javascript?](https://stackoverflow.com/questions/5187530/variable-variables-in-javascript) – General Grievance Mar 30 '21 at 14:55
  • If not, what error are you getting? We don't know what `v` is. – General Grievance Mar 30 '21 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. – phuzi Mar 30 '21 at 15:04

1 Answers1

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()

phuzi
  • 12,078
  • 3
  • 26
  • 50