Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add double quotes to string which is stored in variable

I have variable which i am getting from DB string url, But the url does not have quotes to url i need to add the quotes to it below is my code.

 var audioUrl
 url is having string like http://xxxxx/xxx/xx-xx-123.m4a without double quotes
 audioUrl= (data.url)

 i need convert data.url value to "http://xxxxx/xxx/xx-xx-123.m4a"

       Circle Jplayer
       var audio="http://xxxxx/xxx/xx-xx-123.m4a"
       var myOtherOne = new CirclePlayer("#jquery_jplayer_2",
        {
            m4a: audio,
        }
like image 693
kitty sarvaj Avatar asked Dec 07 '25 08:12

kitty sarvaj


2 Answers

If possible, I'd use ES6 syntax for this:

`"${data.url}"`
like image 114
Jonah Avatar answered Dec 08 '25 22:12

Jonah


var audioUrl = "\""+ data.url+  "\""; 

Whatever your get audioUrl and you want to wrap it with ", you need to put them and escape inner ones with . Above will result in:

 "http://xxxxx/xxx/xx-xx-123.m4a"

OR if you are using the single quotes then no need to use the escape character.

var audioUrl = '"'+ data.url+  '"'; 
like image 42
Ankit Agarwal Avatar answered Dec 08 '25 22:12

Ankit Agarwal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!