How to remove backslash escaping from a javascript var?

后端 未结 8 948
轮回少年
轮回少年 2020-12-09 01:58

I have this var

var x = \"
\";

Which is

8条回答
  •  [愿得一人]
    2020-12-09 02:19

    Let me propose this variant:

    function un(v) { eval('v = "'+v+'"'); return v; }
    

    This function will not simply remove slashes. Text compiles as code, and in case correct input, you get right unescaping result for any escape sequence.

提交回复
热议问题