Put quotes around a variable string in JavaScript

后端 未结 12 1968
时光说笑
时光说笑 2020-12-05 02:46

I have a JavaScript variable:

var text = \"http://example.com\"

Text can be multiple links. How can I put \'\' around the variable string?<

12条回答
  •  借酒劲吻你
    2020-12-05 03:12

    This can be one of several solutions:

    var text = "http://example.com";
    
    JSON.stringify(text).replace('\"', '\"\'').replace(/.$/, '\'"')
    

提交回复
热议问题