-7

Possible Duplicate:
Double quote in JavaScript string

var array=["famous quote by Shakespear is",""to be or not to be""]

How do I escape the blockquote in the second element of the array which uses " for delimiting elements?

Community
  • 1
  • 1
Gordon
  • 1
  • 1
  • 6

2 Answers2

2

Use a backslash:

var str = "famous quote by Shakespear is, \"to be or not to be\"";
var str = 'famous quote by Shakespear is, \'to be or not to be\'';

Or just mix the types of quotes:

var str = "famous quote by Shakespear is, 'to be or not to be'";
var str = 'famous quote by Shakespear is, "to be or not to be"';
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
2

You can escape with a backslash or use single quotes around the string:

var array=["famous quote by Shakespear is","\"to be or not to be\""];
var array=["famous quote by Shakespear is",'"to be or not to be"'];

Single and double quotes are interchangeable as long as you pair them correctly.

Dennis
  • 32,200
  • 11
  • 64
  • 79