3

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,
        }
kitty sarvaj
  • 517
  • 5
  • 10
  • 24

4 Answers4

9

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

`"${data.url}"`
Jonah
  • 15,806
  • 22
  • 87
  • 161
4
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+  '"'; 
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62
  • Can you please upvote the answer so that when other see it they will find that the answer has been fully accepted by you. – Ankit Agarwal Jun 28 '17 at 07:23
0

This is the simplest way

var audioUrl = '"' + (data.url) + '"'
EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40
0

This is a problem that comes up all the time for me and it does get frustrating. A simple solution is to create global variables and use them in your strings as needed like so:

var singleQuote = " ' ";

var doubleQuote = ' " ';

Hope this helps others.

Eggcellentos
  • 1,570
  • 1
  • 18
  • 25