I was wondering how we can add double quotes in a string in javascript, as I have variable, which can be string of string, like this
var str = 'Hello, "World","Something", Else';
Thanks
Here are the few possible ways to add double quotes in string in javascript
var str = 'Your "String"'; //use single quotes for your string
var str2 = "Your \"String\""; //escape your doublequotes
var str3 = "Your "String""; //use it as html special chars
document.write(str + "<br/>");
document.write(str2+ "<br/>");
document.write(str3+ "<br/>");
This will have output as below
Your "String"
Your "String"
Your "String"
OR
If you need to add single quotes
var text = "Your String"
var quoteText = `'${text}'`
console.log(quoteText)
In the above code, we are using template literals.
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly