Reputation: 1728
So many related questions out there, but none satisfyingly answered using javascript (no jQuery).
I wish to add quotes around a variable in a string I'm building. My string itself should contain single quotes within it like so:
'{'a'}'
I can get:
'{a}'
When I try to add single quotes around the key a
I get:
'{\'a\'}'
I've used both of the following syntax with the same result. Any suggestions??
concat('\'','a','\'')
'\''+'a'+'\''
See line 39 of this code: https://repl.it/@mike_butak/LiveForHisPleasureHeReallyIsThere
Thanks!
Upvotes: 0
Views: 5208
Reputation: 675
Having a hard time replicating your issue! See:
var temp = '\'{\'a\'}\'';
console.log('s' + temp + 's');
I'd definitely recommend demonstrating the issue you are asking about in a console print or in a readily available editor online before posting a question!
As per your comment, updating to make it part of a variable assignment. Still unclear what the issue is!
Upvotes: 1
Reputation: 51185
Like this?
console.log("'{'a'}'")
To expand on this, when you are building the string, just use "
around the string, and '
within the string.
Upvotes: 1